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

StackOverflow https://stackoverflow.com/questions/18134148

Вопрос

I'm on a fedora 19 x86_64 computer, with mingw64 and all the relevant packages installed. 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. As soon as I did, I started to get linker errors related to 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):

$ 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

But with mingw32 it compiles like a charm:

$ 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? Does it compile with the windows version of mingw?

Edit: actually it did, so it must be a bug in the fedora mingw64 package

Это было полезно?

Решение 2

In fact I still keep getting the same results, so I will definitely report it. Thanks

Другие советы

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. It works for me.

I encountered similar issue of undefined reference to Interlocked* functions. As far as I know, mingw64 rev2 from MinGWBuilds project (on sf) is working, while rev3 is not working. So I belive it is something changed in MinGW64.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top