Reputation: 3890
I'm building a library with SCons.
The filename of a library that I want to be linked to doesn't start with the usual "lib" prefix.
I read ld documentation and check in my console running GCC that, if I put -l:filename.so
a library named "filename.so" will be searched through the library paths specified.
When I try this solution into my SConscript file, apparently Scons keeps the colon in the front of the library name, but it removes the ".so" part, so the library cannot be found because its filename contains the .so extension.
Update: A brief example.
env = Environment()
hello = env.Program(["hello.cc"], LIBPATH=['.'], LIBS=[':kntlm.so'])
This Scons script try to compile the source "hello.cc" (only a Hello world, not using any library). In the same directory I copied, only for this example purpose, a library from my system. I named it "kntlm.so" instead its real name (libkntlm.so).
From a terminal, I can run this:
g++ -o hello hello.o -L. -l:kntlm.so
And GCC compiles it without any problem.
If I try to run Scons, I get the following executed:
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o hello hello.o -L. -l:kntlm
/usr/bin/x86_64-linux-gnu-ld: cannot find -l:kntlm
collect2: error: ld returned 1 exit status
scons: *** [hello] Error 1
scons: building terminated because of errors.
As you can see, the GCC that Scons executed include the "-l:kntlm", but it removed the ".so" from the end, so the library file cannot be found
Do you know how can I specify a filename for a library instead this weird substitution?
Thanks in advance
Upvotes: 0
Views: 1403
Reputation: 4052
The items in the LIBS
variable are meant to be the stem part of each of your libraries only. SCons will add a prefix and suffix (LIBLINKPREFIX
and LIBLINKSUFFIX
, respectively) to them automatically when compiling the final "link" command.
In your case you should simply add the "-l:kntlm.so
" option to the variable LINKFLAGS
directly:
env = Environment()
hello = env.Program(["hello.cc"], LIBPATH=['.'], LINKFLAGS=['-l:kntlm.so'])
Note, that this isn't platform-independent anymore...which is the whole point behind using the LIBS
list under normal circumstances.
And yes, the User Guide tells you to not set a "-l
" option via the "LINKFLAGS
", but this is an exception from the default rule.
Finally, if you create shared libraries you'll have to use SHLINKFLAGS
instead.
Upvotes: 1