如何强制使用静态库而不是共享库?
在我的 SConscript 中,我有以下行:
Program("xtest", Split("main.cpp"), LIBS="mylib fltk Xft Xinerama Xext X11 m")
如何让 scons 使用 mylib.a 而不是 mylib.so,同时与其他库动态链接?
编辑:希望尽可能少地使用特定于平台的黑客。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递包含在文件节点中的完整文件路径将强制静态链接。例如:
将生成以下链接器命令行 请
注意“-l”标志如何不传递给此 LIBS 条目的链接器。这有效地强制静态链接。另一种方法是修改 LINKFLAGS 以获得您想要的内容,但需要注意的是,您将绕过库依赖项扫描器 - 不会检查库的状态以进行重建。
Passing the full filepath wrapped in a File node will force static linking. For example:
Will produce the following linker command line
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.
为了使这个平台独立,您可以将 env['SHLIBSUFFIX'] 附加到您想要使用的库上。 env['SHLIBSUFFIX'] 为您提供共享库的环境后缀。
您还可以使用 ['SHLIBPREFIX']、['LIBPREFIX']、['LIBSUFFIX'] 和 ['PROGSUFFIX'],它们对于这种情况都很有用。
编辑:
显然我没有表达清楚,所以我会澄清。
这些查找的返回值是平台使用的前/后缀的字符串。这样你就可以在各个平台上引用你需要的文件了。请注意,您不能将其用作纯字符串,它必须按照 BennyG 的建议嵌入为文件节点。无论如何,使用节点是最好的解决方案,因为文件节点比字符串更通用。
希望这有帮助。
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.