Reputation: 1401
My situation is I have a library that doesn't have a "lib" prefix. I'd like to link against it, and I can't recompile it (it's actually a Python module).
Now, if you use the '-l' flag with GCC or clang, then the lib prefix is automatically added and the library is not found. For GCC, I can use '-l:mylib.so' to get it to link against an arbitrary file.
However, this doesn't work for clang. Is it possible to get clang to link against a particular library without the 'lib' prefix?
Upvotes: 8
Views: 10857
Reputation: 9972
This answers the question, but from a somewhat different angle. See the related question C++ 11 code compiles with `clang++`, but not with `clang -x c++`.
The gcc documention states:
Object files are distinguished from libraries by the linker according to the file contents.
This does not work if you use clang++ -x c++
. Instead, the library file is taken as a C++ source file, and this generates a million or so compile errors. And you can't put the library file before the -x c++
, because the needed symbols won't be linked in.
One obvious solution is to rename your source files to have a .cpp
extension, so the -x
switch is unnecessary (or use symbolic links). But this might be a pain to add to your build system.
Another solution, directly related to the OP's question, is to specify the library via the flags:
-L. -l:mylib.foo
If the library is not in the local directory, change the dot .
accordingly.
Upvotes: 8