简体   繁体   English

Boost库的多重链接

[英]Multiple linkage of boost libraries

Is there can be a problem like ODR if application link with some libraries of boost and another library that compiled with link with boost? 如果应用程序与一些boost的库链接,而另一个应用程序通过boost的链接编译,是否会出现像ODR这样的问题?

Example: foo.exe link with boost-*.lib and bar.lib , previously when compiling bar.lib it was link with boost-*.lib too. 示例: foo.exeboost-*.libbar.lib ,以前在编译bar.lib时也与boost-*.lib链接。

Libraries build as Multi-threaded in terms of MSVC. 就MSVC而言,库构建为多线程的。

I had a similar issue with libcURL and OpenSSL with static linking. 我在使用静态链接的libcURL和OpenSSL中遇到了类似的问题。 The libCURL library uses OpenSSL for https download, and needs to link to OpenSSL when compiling it. libCURL库使用OpenSSL进行https下载,并且在编译时需要链接到OpenSSL。 My observation is: 我的观察是:

  • If you link libcURL to OpenSSL, then you don't need to link your program to OpenSSL when it uses libCURL 如果将libcURL链接到OpenSSL,则当它使用libCURL时,无需将程序链接到OpenSSL
  • If you link libcURL to OpenSSL and also link your program to OpenSSL, MSVC will complain that multiple and conflicting implementations exist. 如果将libcURL链接到OpenSSL,并且还将程序链接到OpenSSL,则MSVC将抱怨存在多个冲突的实现。

What I recommend is that you try to link to bar.lib without that boost library, and see if it works. 我建议您尝试在没有该Boost库的情况下链接到bar.lib ,然后查看它是否有效。 If it compiles, you're good without it. 如果可以编译,那么没有它,你会很好。 If you get an undefined reference error, then you need to link to it. 如果收到未定义的参考错误,则需要链接到它。 That's the worst case scenario. 那是最坏的情况。

Mixing multiple versions of Boost (including header only libraries) in the same process is always a bad idea. 在同一过程中混合多个版本的Boost(包括仅包含标头的库)总是一个坏主意。 Boost provides no API nor ABI guarantees, if two differing versions ever touch one another then expect memory corruption and worse. Boost既不提供API也不提供ABI保证,如果两个不同的版本相互接触,则可能会导致内存损坏甚至更糟。

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

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