“将DLL Boost库与静态运行时混合是一个非常糟糕的主意..." [英] "Mixing a dll boost library with a static runtime is a really bad idea..."

查看:274
本文介绍了“将DLL Boost库与静态运行时混合是一个非常糟糕的主意..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio解决方案中有两个项目.一种构建静态的LIB,另一种构建动态的DLL.两者都使用静态运行时链接(/MT和/MTd),并且都使用Boost. Boost不是我的决定-我想放弃它,但是我被委员会否决了.

I have two projects in a Visual Studio solution. One builds a static LIB, the other builds a dynamic DLL. Both use static runtime linking (/MT and /MTd), and both use Boost. Boost was not my decision - I wanted to chuck it but I was overruled by committee.

LIB可以很好地构建,但是DLL咳出了来自auto_link.hpp的错误(第354行):与静态运行时环境混合dll boost库是一个非常糟糕的主意...".

The LIB builds fine, but the DLL coughs up an error from auto_link.hpp (line 354): "Mixing a dll boost library with a static runtime is a really bad idea...".

#if (defined(_DLL) || defined(_RTLDLL)) && defined(BOOST_DYN_LINK)
#  define BOOST_LIB_PREFIX
#elif defined(BOOST_DYN_LINK)
#  error "Mixing a dll boost library with a static runtime is a really bad idea..."
#else
#  define BOOST_LIB_PREFIX "lib"
#endif

我没有定义BOOST_DYN_LINK.自从我构建DLL(定义了_USRDLL和_​​WINDLL)以来,Boost似乎取得了飞跃,我必须要动态运行时链接(定义了_DLL的/MD或/MDd)或针对Boost的DLL链接.这是不正确的,因为我特别要求进行静态链接(/MT或/MTd).

I did not define BOOST_DYN_LINK. It seems Boost is making a leap that since I am building a DLL (_USRDLL and _WINDLL are defined), I must want dynamic runtime linking (/MD or /MDd, which defines _DLL) or DLL linking against Boost. This is incorrect as I specifically asked for static linking (/MT or /MTd).

我针对Boost的不正确假设提交了错误报告,但是不能帮助我使用该库.在报告中,Boost维护人员坚持要求我进行设置(尽管审计显示我不是); Boost会至少处理30个文件).我在Boost邮件列表中找到了一个答案更改我的项目设置以适应Boost.

I filed a bug report against Boost for its incorrect assumptions, but that does not help me with using the library. In the report, the Boost maintainers insist that I am setting it (despite the fact that an audit showed I am not; and Boost manipulates it in at least 30 files). I found one answer on the Boost mailing list, which essentially states to change my project settings to accomodate Boost.

更改为动态运行时链接(/MD和/MDd)是不可行的,因为选择静态链接是(1)出于安全考虑,(2)另一个库使用静态链接.这是不可商议的-我们别无选择.

Changing to Dynamic Runtime Linking (/MD and /MDd) is not feasible since static linking was chosen (1) due to security considerations, and (2) another library uses static linking. This is non-negotiable - we have no choice.

为清楚起见(TLDR)进行总结:我想对所有内容使用静态链接,而我的输出程序是D​​LL(不是静态LIB,不是EXE).一切都在DLL中静态链接.

To summarize for clarity (TLDR): I want to use static linking for everything, while my output program is a DLL (not a static LIB, not an EXE). Everything is linked statically within the DLL.

有人知道如何在Windows上使用此库通过静态链接构建DLL吗?

Does anyone know how to use this library on Windows to build a DLL with static linking?

推荐答案

此问题确实是boosts设置的问题. 由于某些未知的原因(我无法确定自己是逻辑的-因为它没有效果). Boost Python将强制动态链接boost,无论用户选择什么选项

This issue is indeed a fault with boosts settings. For some unknown reason (that I cannot determine to be logical - as it has not effect). Boost Python will force dynamic linking of boost, regardless of user options

简而言之,如果您的项目中包含boost-python,则boost不正确地阻止了boost与/MT开关的静态链接.

In short, if you have boost-python in your project, boost incorrectly prevents static-linking of boost with the /MT switch.

通过在包含boost头之前定义BOOST_PYTHON_STATIC_LIB,可以轻松解决此问题.

This problem is resolved easily by defining BOOST_PYTHON_STATIC_LIB before including the boost headers.

这篇关于“将DLL Boost库与静态运行时混合是一个非常糟糕的主意..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆