Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
大家好!
我在 linux 上使用 gcc 来创建一个共享库。该库本身没有代码,但链接到同样使用 gcc 构建的几个静态库(档案)。我需要通过我的共享库导出静态库的符号。发生的情况是生成的共享库太小,它实际上不包含上述静态库提供的任何符号。我也尝试使用导出符号的地图,但这根本没有帮助。你们中的任何人都可以提出解决方案!
提前 10 倍
您需要链接器的--whole-archive选项来拉入所有静态档案:
--whole-archive
gcc -shared -o libwhatever.so -Wl,--whole-archive -lstatic -Wl,--no-whole-archive
-Wl是必需的,因为--whole-archive它是一个链接器选项。
-Wl
为了做到这一点,libstatic.a 中的代码需要经过正确编译才能在共享对象中使用(即-fpic在需要的平台上使用)。
-fpic