简体   繁体   English

使用Boost与Mingw链接C ++代码时出现问题

[英]Problem linking c++ code using boost with mingw

I'm trying to port/build some of my code written for gcc (on linux) as a dll on windows. 我试图将一些为gcc(在Linux上)编写的代码移植/构建为Windows上的dll。 First I tried to build in under VC++ but there were so many errors/warnings (mainly in VC's own include files, which didn't really make much sense to me :)) so I installed MinGW distro (which includes Boost libraries). 首先,我尝试在VC ++下进行构建,但是有太多的错误/警告(主要在VC自己的包含文件中,这对我而言并没有多大意义:)),因此我安装了MinGW发行版(包括Boost库)。 Compilation went quite smoothly, however linking failed with undefined references to functions from boost libraries. 编译进行得很顺利,但是由于对boost库中函数的未定义引用而导致链接失败。 The "-t" parameter showed that the linker doesn't actually use the boost libraries for some reason (yes, the -L path is correct, the libraries are there, linker doesn't complain when I use -l). “ -t”参数表明链接器实际上出于某种原因未使用boost库(是的,-L路径正确,库在那里,当我使用-l时链接器没有抱怨)。

After much googling I found out that the order is the problem, that I have to place my -l parameters after all my .o files (because of dependencies). 经过大量的搜索之后,我发现顺序是问题所在,我必须将-l参数放在所有.o文件之后(由于依赖关系)。 This seemed to solve all the problems except one undefined reference to thread library. 除了一个未定义的对线程库的引用,这似乎解决了所有问题。 Again -t showed that this library is actually not used by the linker (not in the list) the others are (I use boost_system and boost_date_time as well). 再次-t表明该库实际上未被链接器使用(不在列表中),而其他链接器却使用了(我也使用boost_system和boost_date_time)。 I played with the order of the parameters again but the result was the same. 我再次按参数顺序进行操作,但结果相同。 Any idea what am I missing? 知道我想念什么吗?

The error is: 错误是:

c:/x5/cpp/build//timed_cond.o:timed_cond.cpp:(.text$_ZN5boost6detail24basic_condition_variable7do_waitINS_11unique_lockINS_5mutexEEEEEbRT_NS0_7timeoutE[bool boost::detail::basic_condition_variable::do_wait<boost::unique_lock<boost::mutex> > (boost::unique_lock<boost::mutex>&, boost::detail::timeout)]+0x246): undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'

I use same versions of Boost library (1.44.0) on both platforms 我在两个平台上都使用相同版本的Boost库(1.44.0)

Ok, I found the answer. 好的,我找到了答案。 Looks like the problem is in boost libraries being static in MinGW-distro. 看起来问题出在MinGW发行版中的boost库是静态的。 Normally they are configured to be linked dynamically and that caused above issue. 通常,它们被配置为动态链接,从而导致上述问题。 This answer explains it... 这个答案解释了...

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

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