![](/img/trans.png)
[英]Can't compile with ICU library - undefined reference to 'u_strlen_3_6'
[英]Can't compile shared library under Windows due to undefined reference
我为Linux
和Windows
使用相同的waf
脚本来编译程序的shared-library
(它能够在运行时加载共享库)。
为了创建这个库,我导入了主程序的一些头文件,这样我就可以在库中调用主程序的函数,并且在运行时解析符号,这在Linux下有效。
在 Windows 下,我无法构建库,因为它说我在库中调用的主程序的每个函数都undefined reference
。
在这种情况下, Windows
和Linux
之间有什么区别? 为什么我必须在Windows
下的链接时解析符号? 有没有旗帜或类似的东西来避免这种情况?
Linux 允许共享库中的未解析符号,但 Windows 不允许。 我不知道这种差异的原因。 例如,在https://lists.gnu.org/archive/html/libtool/2007-04/msg00070.html 中,您可以看到一种观点,即在 Linux 上“允许在共享库中进行循环引用”。
在 Windows 上,您可以使用/FORCE:UNRESOLVED
链接器参数获得与在 Linux 上相同的行为(请参阅https://docs.microsoft.com/en-us/cpp/build/reference/force-force-file-output?view =msvc-170 ),但它有一个限制,即您的 DLL 必须有一个入口点。
在 Linux 上,您可以使用-Wl,-no-undefined
链接器参数获得与在 Windows 上相同的行为。 此外,您可以使用参数-Wl,--no-allow-shlib-undefined
仅在您链接的共享库中禁止未定义的符号(请参阅https://linux.die.net/man/1/ld )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.