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 8631607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:14:30+00:00 2026-06-12T09:14:30+00:00

I have a project in C++ which currently is not linked against any external

  • 0

I have a project in C++ which currently is not linked against any external dynamic library. I’m thinking about using some of boost libraries in future which need to be built (not header-only). For now, in the stage of development, I build my project with three different tool chains: g++, LLVM/Clang++ and Intel C++, the platform is Linux. These compilers, AFAIK, are binary compatible with each other, e.g. g++-compiled app can use Intel C++-compiled dynamic library.

I’ve built boost binaries and installed them into different folders. e.g. build_gcc, build_icc. Then I added paths to these folders to the system LIBRARY_PATH. The question is: if I now build my project with either g++ or Intel C++ and link some dynamic library, e.g. write

-lboost_math_tr1

in the makefile, how does the linker decide which exact library file to link against if the binaries from different compilers are compatible with each other?

The motivation of the question is simple: Intel C++ is an optimizing compiler, so if I build things with it, I expect them to be linked against dynamic library compiled with Intel C++ compiler, not against the one compiled with g++. Of course, I know that I can simply use multiple conditional statements in the makefile to set the exact directories with library binaries for each used tool chain but it is just a bit inconvenient. I am wandering, is the linker smart enough to recognize which exact shared library file it should use or does it simply use the first occurrence found in the system LIBRARY_PATH?

  • 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-06-12T09:14:30+00:00Added an answer on June 12, 2026 at 9:14 am

    the linker won’t know. if the first found library is incompatible, it will even bail out, rather than search all libs until it finds a compatible one.

    confirm something like:

    $ cat foo.c
    int main() {
      return 0;
    }
    $ mkdir bar
    $ touch bar/libm.so
    $ gcc foo.c -o foo -Lbar -lm
    /usr/bin/ld: error: b/libm.so: file is empty
    collect2: error: ld returned 1 exit status
    

    otoh, the beauty of dynamic linking lies in being able to exchange the dylib with a better one, without having to recompile.
    so you can link against the g++ version, but if performance is poor install the icc version on the target host (on a place that will be searched for before the g++-version) and your application will magically use it (as long as they are compatible).

    you could also use the LD_LIBRARY_PATH variable to search for libraries in a non-standard location when running your application:

    LD_LIBRARY_PATH=/path/to/super/libs/ ./app-dylinked-with-generic-libs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that produces a shared library which is linked against another,
I have to reuse a major C++ project which is currently developed inside eclipse,
Currently, I have a Maven project which inherits from a parent pom defining two
I am currently doing a project in which I have to request data from
I have a project which has some lib's associated with it (in Build Path).
I have a lot of legacy code which I currently compile using an antiquated
I currently have a project which includes a ton of externals which needs to
Currently I have 1 Guice module in my project which defines all bindings. Now
I have a project here which, currently, uses one pom.xml ( link ) to
I have a project which builds correctly from the command line. On one of

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.