简体   繁体   English

在mingw64上对带有boost.thread的InterlockedCompareExchange的未定义引用(但在mingw32上未引用)

[英]Undefined reference to InterlockedCompareExchange with boost.thread on mingw64 (but not on mingw32)

I'm on a fedora 19 x86_64 computer, with mingw64 and all the relevant packages installed. 我在安装了mingw64和所有相关软件包的fedora 19 x86_64计算机上。 I was working on a personal c++ project, and i decided to make it thread-safe, and so I decided to give Boost.thread synchronization objects a try. 我当时正在从事一个个人c ++项目,因此决定使其成为线程安全的,因此我决定尝试使用Boost.thread同步对象。 As soon as I did, I started to get linker errors related to InterlockedCompareExchange. 一经发现,我就开始出现与InterlockedCompareExchange相关的链接器错误。 The following test program illustrates my point: 以下测试程序说明了我的观点:

#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>

int main()
{
    boost::shared_mutex mtx;
    boost::unique_lock<decltype(mtx)> lck{mtx};
}

Here's the command line (I put -lboost_thread-mt because there's no non-multithreaded version, which makes sense): 这是命令行(我放了-lboost_thread-mt,因为没有非多线程版本,这很有意义):

$ x86_64-w64-mingw32-g++ -std=c++11 test.cpp -o test -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lboost_thread-mt -lboost_system $ x86_64-w64-mingw32-g ++ -std = c ++ 11 test.cpp -o test -I / usr / x86_64-w64-mingw32 / sys-root / mingw / include -L / usr / x86_64-w64-mingw32 / sys-root / mingw / lib -lboost_thread-mt -lboost_system

/tmp/cc4Wh6PO.o:test.cpp:(.text$_ZN5boost12shared_mutex28interlocked_compare_exchangeINS0_10state_dataEEET_PS3_S3_S3_[_ZN5boost12shared_mutex28interlocked_compare_exchangeINS0_10state_dataEEET_PS3_S3_S3_]+0x2f): undefined reference to `InterlockedCompareExchange' collect2: error: ld returned 1 exit status /tmp/cc4Wh6PO.o:test.cpp:(.text$_ZN5boost12shared_mutex28interlocked_compare_exchangeINS0_10state_dataEEET_PS3_S3_S3_[_ZN5boost12shared_mutex28interlocked_compare_exchangeINS0_10state_dataed]=S3=S3

But with mingw32 it compiles like a charm: 但是使用mingw32时,它的编译就像一个魅力:

$ i686-w64-mingw32-g++ -std=c++11 test.cpp -o test -I/usr/i686-w64-mingw32/sys-root/mingw/include -L/usr/i686-w64-mingw32/sys-root/mingw/lib -lboost_thread-mt -lboost_system $ i686-w64-mingw32-g ++ -std = c ++ 11 test.cpp -o test -I / usr / i686-w64-mingw32 / sys-root / mingw / include -L / usr / i686-w64-mingw32 / sys-root / mingw / lib -lboost_thread-mt -lboost_system

My question is: am I doing something wrong or is it a bug in mingw64? 我的问题是:我是在做错什么还是mingw64中的错误? Does it compile with the windows version of mingw? 它可以与Windows版本的mingw一起编译吗?

Edit: actually it did, so it must be a bug in the fedora mingw64 package 编辑:实际上确实如此,所以它一定是fedora mingw64软件包中的错误

Based on this page http://sourceforge.net/apps/trac/mingw-w64/wiki/Building%20Boost , you can add define=BOOST_USE_WINDOWS_H to avoid that linking error. 基于此页面http://sourceforge.net/apps/trac/mingw-w64/wiki/Building%20Boost ,您可以添加define = BOOST_USE_WINDOWS_H来避免该链接错误。 It works for me. 这个对我有用。

In fact I still keep getting the same results, so I will definitely report it. 实际上,我仍然保持相同的结果,因此,我一定会报告。 Thanks 谢谢

I encountered similar issue of undefined reference to Interlocked* functions. 我遇到过类似的问题,未定义的对Interlocked *函数的引用。 As far as I know, mingw64 rev2 from MinGWBuilds project (on sf) is working, while rev3 is not working. 据我所知,MinGWBuilds项目(位于sf上)的mingw64 rev2正在运行,而rev3无法运行。 So I belive it is something changed in MinGW64. 所以我相信这是MinGW64中发生的变化。

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

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