Reputation: 208
I have SCons code in which I am using SConscripts to build different directories separately. In my Src
directory, my SConscript builds a shared library, and then returns the resulting Node as the Python variable libMyLibrary
. I typically use the install
option to copy this library to a directory that is on my system's LD_LIBRARY_PATH
(I'm using OpenSUSE).
So far, so good. Now, in another directory, Src/Test
, another SConscript imports libMyLibrary
and builds some Programs using code like this:
env.Program('myProgram', 'myProgram.cpp', LIBS=[env['LIBS'], libMyLibrary])
The program then gets installed to my local bin
folder. This code does track the library dependency and build the program, but the problem is that since the library is in a sub-directory (Src
), that sub-directory gets included in the linker command. Here is an abbreviated example of the linker command that SCons generates:
g++ -o Src/Test/myProgram Src/Test/myProgram.o Src/libMyLibrary.so
I believe this happens because the Node,libMyLibrary
, is essentially a path. The problem is that when I try to run the program, it is not looking for libMyLibrary.so
in my library folder, but rather Src/libMyLibrary.so
, and of course it doesn't find it.
I do NOT want the libraries I build to be installed in sub-directories of my install folder.
I already add the Src
folder to LIBPATH
, so SCons adds the -LSrc
option to the linker command, but that doesn't solve the problem. My preference would be that when I add a Node, the path should automatically get parsed out to add the appropriate -L
and -l
options.
I know that I can get around this problem by adding the string 'MyLibrary'
to the LIBS
variable instead of the libMyLibrary
Node, but then I have to explicitly tell SCons that each Program Depends()
on libMyLibrary
. It seems very inefficient to short-circuit SCons's built-in dependency tracking this way. Does anyone know the correct, SCons-y way to do this?
Upvotes: 0
Views: 275
Reputation: 4052
I'm referring to your latest comment: It looks to me as if this is not really a SCons problem, but more a general linker question (XY problem). Are you perhaps simply searching for RPATH
? Please also check this old SO question: scons executable + shared library in project directory
Upvotes: 0