How to force use of static library over shared?

假装没事ソ 提交于 2019-12-18 19:06:26

问题


In my SConscript I have the following line:

Program("xtest", Split("main.cpp"), LIBS="mylib fltk Xft Xinerama Xext X11 m")

How do I get scons to use mylib.a instead of mylib.so, while linking dynamically with the other libraries?

EDIT: Looking to use as few platform specific hacks as possible.


回答1:


Passing the full filepath wrapped in a File node will force static linking. For example:

lib = File('/usr/lib/libfoo.a')
Program('bar', 'main.c', LIBS = [lib])

Will produce the following linker command line

g++ -o bar main.o /usr/lib/libfoo.a

Notice how the "-l" flag is not passed to the linker for this LIBS entry. This effectively forces static linking. The alternative is to modify LINKFLAGS to get what you want with the caveat that you are bypassing the library dependency scanner -- the status of the library will not be checked for rebuilds.




回答2:


To make this platform independent you append the env['SHLIBSUFFIX'] onto the library you want to use. env['SHLIBSUFFIX'] gives you this environments suffix for shared libraries.

You also have the ['SHLIBPREFIX'], ['LIBPREFIX'], ['LIBSUFFIX'] and ['PROGSUFFIX'], all useful for situations like this.

Edit:

I obviously haven't made myself understood, so I will clarify. The return value of these lookups are strings to the pre/suffixes that platform uses. In that way you can refer to the file you need on each platform. Note that you cannot use it as a pure string, it has to be embedded as a file node as BennyG suggests. Working with nodes are anyway the best solution as file nodes are much more versatile than a string.

Hope this helps.



来源:https://stackoverflow.com/questions/2986734/how-to-force-use-of-static-library-over-shared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!