开发者

Why does the -export-dynamic flag not apply to archives?

If I compile and link an executable with the -export-dynamic flag, it does开发者_运维技巧n't apply to symbols stored in archives that are linked. The flag only on exports symbols for objects that are linked that aren't in archives. Can someone explain why this would be?


The problem seems to be that .o files inside .a files are only linked if they are needed by the executable (apparently it's called "dead-stripping"). In my case, the symbols are only required by a shared library that is explicitly opened with dl commands. I can link with the --whole-archive option (on GNU, at least), which will force the linking of all the objects in the archive.


Because archives don't import or export anything.

A '.a' file is just a compendium of '.o' files. There is no concept of import and export until they are linked, either into an executable or a shared library. There is no data structure in an 'ar' archive to store such a thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜