如何强制使用静态库而不是共享库? [英] How to force use of static library over shared?

查看:132
本文介绍了如何强制使用静态库而不是共享库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SConscript中,有以下一行:

In my SConscript I have the following line:

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

在与其他库动态链接的同时,如何让scons使用mylib.a而不是mylib.so?

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

希望使用尽可能少的特定于平台的技巧.

Looking to use as few platform specific hacks as possible.

推荐答案

传递包裹在File节点中的完整文件路径将强制进行静态链接.例如:

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

请注意该LIBS条目如何不将"-l"标志传递给链接器.这有效地强制了静态链接.另一种方法是修改LINKFLAGS,以绕过库依赖扫描程序的警告来获得所需的内容-不会检查库的状态以进行重建.

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.

这篇关于如何强制使用静态库而不是共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆