Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:53+00:00 2026-05-24T04:03:53+00:00

Start with shared library libA.so that is in /some/lib. I build library (libB.so) that

  • 0

Start with shared library libA.so that is in /some/lib.
I build library (libB.so) that depends on a capability in libA.so. So, when creating libB.so, I include -L/some/lib -lA on the g++ command line.
libB.so will also reside in /some/lib.

Now, I’m building an executable that will use libB.so. I provide the expected -L/some/lib and -lB to the g++ linker. But I get an error because it can’t find “libA.so”. If I add “-lA” to the linker line, the program links.

I don’t understand why it doesn’t find “libA.so”. I certainly don’t understand why including “-lA” on the linker line lets it find it. It appears to already know that it needs libA.so, and libA.so is in the same path as libB.so.

Can someone explain this? I don’t like the idea of having to explicitly put “-lA” in every executable that wants to link libB.so. Did I do something else wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:03:53+00:00Added an answer on May 24, 2026 at 4:03 am

    While you are linking against libB only, the linker looks for libA, but cannot find it, because it isn’t in a findable path for the linker/loader. You have to set LD_LIBRARY_PATH (and/or LD_RUN_PATH) during the linking stage, or otherwise link libB with -rpath /some/lib.

    Just pretend for a minute that libB is itself an executable, let’s call it foo. You couldn’t just say ./foo at the command line because libAwouldn’t be found (check ldd foo to examine the loader paths). Instead, you need

    LD_LIBRARY_PATH=/some/lib ./foo
    

    or you need to compile with rpath. (In g++, you’d say g++ -Wl,-rpath,/some/lib ... to pass the option to the linker.) The same load-time resolution process applies to dynamic libraries themselves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.