I use gcc more than any other compiler, so I will shape my example with this compiler suite, but i have experienced this problem with almost all the suite that i have tried like gcc, mingw, clang and msvc.
gcc offers this flags:
-lyou write the namefoo, gcc will find a corrisponding library namedlibfoo-Lyou append the path where the libs lives and gcc tries to match the required libraries to the ones that it finds in that path-rpathbasically a pool of different path for the same lib so the executable is “smart” enough to look for alternatives if he needs one.
the problem is big for me, no one of this solves my problem and each one of this flags suffer the same problem: ambiguity.
if I just want to link a library that i know there is no way to do this without including a dose of ambiguity in the best case scenario, what i want is:
- linking 1 specific library only, and only the 1 that I specify with a precise name and path
- avoid auto-completion mechanism like the one on the name given to
-lbecause my libs are namedfoo.sonotlibfoo.so - relative path for the linked libs
- only consider the explicitly given set of libraries, no other automation of any kind should be involved, no pool of libs, no search-paths, no nothing else, I prefer list of errors instead of an executable linked to a random library
I often deal with different libs in different releases, they often share the same name for historical and compatibility reasons, it’s a nightmare compiling and linking with gcc because I never got the one that I want linked to my executable.
Thanks.
The easiest way to do this is to simply specify the library.
gcc -o test test.o /path/my_library.so /path/to_other_library.aThe obvious downside to this approach if of course that if you move that library then your application won’t work anymore but since you state that you have the libraries at fixed locations it should work in your case.