如何强制使用静态库而不是共享库?

发布于 2024-09-04 16:46:22 字数 219 浏览 3 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就此别过 2024-09-11 16:46:22

传递包含在文件节点中的完整文件路径将强制静态链接。例如:

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

将生成以下链接器命令行 请

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

注意“-l”标志如何不传递给此 LIBS 条目的链接器。这有效地强制静态链接。另一种方法是修改 LINKFLAGS 以获得您想要的内容,但需要注意的是,您将绕过库依赖项扫描器 - 不会检查库的状态以进行重建。

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.

不羁少年 2024-09-11 16:46:22

为了使这个平台独立,您可以将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文