简体   繁体   English

创建共享对象时静态链接lib * .a文件的链接器选项

[英]Linker options to statically link a lib*.a file while creating a shared object

How can I tell the linker that statically link libfoo.a while building the shared object sharedobj.so using gcc/make. 在使用gcc / make构建共享库sharedobj.so时,如何告诉链接器静态链接libfoo.a。

I have tried to pass the LDFLAG options LDFLAGS += -W1 --whole-archive -L/path/to/libfoo -lfoo 我试图通过LDFLAG选项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 我也尝试过通过LDFLAGS选项LDFLAGS + = -W1,静态-L / path / to / libfoo -lfoo

I have also tried to pass LDFLAGS the options LDFLAGS += -W1, Bstatic -L/path/to/libfoo -lfoo 我也尝试过通过LDFLAGS选项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 我还尝试通过LDFLAGS选项LDFLAGS + = -W1,static_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. 我已阅读了许多链接,告诉我该怎么做,但到目前为止,这些链接都无效。

LDFLAGS is just a feature of auto(conf|crap), and linker never looks at it. LDFLAGS只是auto(conf | crap)的功能,链接器从不看它。 Just give all options on the command-line, like: 只需在命令行中提供所有选项,例如:

gcc obj1.o obj2.o ... -shared -o libfoo.so -L/path/to/lib -lbar gcc obj1.o obj2.o ...-共享-o libfoo.so -L / path / to / lib -lbar

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. 然后,当您将其添加为依赖项时,它应该可以工作-就像其他对象(.o)文件一样。

Link ao bo co staticlib.a into libsharedobj.so 将Ao bo co staticlib.a链接到libsharedobj.so

You might think of an library as an archive (.a) of object (.o) files. 您可能会将库视为对象(.o)文件的存档(.a)。 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. 但是,我不清楚是否所有存档都包含在共享库(或exe)中,或者仅包含在所需的那些部分中-我的理解仅仅是所需的内容,但是我有一段时间没有使用* nix了。 For a .so that might mean it won't include and export anything that isn't used by the .so itself. 对于.so,这可能意味着它不会包含和导出.so本身未使用的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM