创建共享对象时静态链接 lib*.a 文件的链接器选项
我如何告诉链接器在使用 gcc/make 构建共享对象 sharedobj.so 时静态链接 libfoo.a 。
我尝试过传递 LDFLAG 选项 LDFLAGS += -W1 --whole-archive -L/path/to/libfoo -lfoo
我也尝试过向 LDFLAGS 传递选项 LDFLAGS += -W1, static -L/path/to/libfoo -lfoo
我也尝试过向 LDFLAGS 传递选项 LDFLAGS += -W1, Bstatic -L/path/to/libfoo -lfoo
我也
尝试向 LDFLAGS 传递选项 LDFLAGS += -W1, statically_linked -L/path/to/libfoo -lfoo
我已经阅读了许多链接,告诉我如何做到这一点,但到目前为止没有一个起作用。
How can I tell the linker that statically link libfoo.a while building the shared object sharedobj.so using gcc/make.
I have tried to pass the LDFLAG options
LDFLAGS += -W1 --whole-archive -L/path/to/libfoo -lfoo
I have also tried to pass LDFLAGS the options
LDFLAGS += -W1, static -L/path/to/libfoo -lfoo
I have also tried to pass LDFLAGS the options
LDFLAGS += -W1, Bstatic -L/path/to/libfoo -lfoo
and
I have also tried to pass LDFLAGS the options
LDFLAGS += -W1, statically_linked -L/path/to/libfoo -lfoo
I have read through a number of links that tell me how to do it but none have worked so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
LDFLAGS 只是 auto(conf|crap) 的一个功能,链接器从不查看它。只需在命令行上给出所有选项,例如:
gcc obj1.o obj2.o ... -shared -o libfoo.so -L/path/to/lib -lbar
LDFLAGS is just a feature of auto(conf|crap), and linker never looks at it. Just give all options on the command-line, like:
gcc obj1.o obj2.o ... -shared -o libfoo.so -L/path/to/lib -lbar
我不太明白,您希望静态库成为共享库的一部分吗?
然后,当您将其添加为依赖项时,它应该可以工作 - 就像其他对象 (.o) 文件一样。
将 ao bo co staticlib.a 链接到 libsharedobj.so
I do not really understand, do you want the static library be part of your shared one?
Then it should work when you add it as a dependency - like the other object (.o) files.
Link a.o b.o c.o staticlib.a into libsharedobj.so
您可能会将库视为对象 (.o) 文件的存档 (.a)。您可以在链接器步骤中以与目标文件类似的方式使用它。
然而,我不清楚是否所有存档都将包含在共享对象库(或 exe)中,还是仅包含所需的部分 - 我的理解只是所需的内容,但我还没有使用 *nix 一段时间。对于 .so 来说,这可能意味着它不会包含和导出 .so 本身未使用的任何内容。
You might think of an library as an archive (.a) of object (.o) files. You can use it in a similar way to object files in your linker step.
It's unclear to me however if all of the archive will be included in the shared object library (or exe) or only those parts required - my understanding was only what is required but I haven't played with *nix for a bit. For a .so that might mean it won't include and export anything that isn't used by the .so itself.