如何在Eclipse中使用MinGW编译boost线程?

hua*_*n68 2 c++ eclipse boost

#include <boost/thread/thread.hpp>
#include <iostream>

using namespace std;

void hello() {
    cout << "Hello world, I'm a thread!" << endl;
}

int main(int argc, char* argv[]) {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

    boost::thread thrd(&hello);
    thrd.join();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我确信上面的代码没有任何问题,因为我已在Microsoft Visual Studio Express Edition上测试过它.但它不能在Eclipse中编译.

我在Windows机器上执行此操作,我使用带有MinGW工具链的Eclipse Kepler,我D:/tool/boost_1_54_0使用此命令在此目录中安装boost ./b2 install --with-thread --libdir=stage/lib --includedir=stage/include --build-type=complete stage toolset=msvc.我已经配置了额外的包含目录,库路径和线程库,这是boost_thread-vc110-mt-1_54libboost_system-vc110-mt-1_54(在Libraries (-l)项目属性> C/C++构建>设置> MinGW C++链接器>库中)?

这是编译的输出,你看到任何线索吗?

15:52:07 **** Incremental Build of configuration Debug for project Cpp2 ****
Info: Internal Builder is used for build
g++ "-LD:\\tool\\boost_1_54_0\\stage\\lib" -o Cpp2.exe "src\\Cpp2.o" -llibboost_thread-vc110-mt-1_54 -llibboost_system-vc110-mt-1_54 
src\Cpp2.o: In function `_static_initialization_and_destruction_0':
D:/tool/boost_1_54_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
D:/tool/boost_1_54_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
D:/tool/boost_1_54_0/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
src\Cpp2.o: In function `thread_exception':
D:/tool/boost_1_54_0/boost/thread/exceptions.hpp:51: undefined reference to `boost::system::system_category()'
src\Cpp2.o: In function `thread_data_base':
D:/tool/boost_1_54_0/boost/thread/win32/thread_data.hpp:123: undefined reference to `vtable for boost::detail::thread_data_base'
src\Cpp2.o: In function `ZN5boost6thread12start_threadEv':
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:180: undefined reference to `boost::thread::start_thread_noexcept()'
src\Cpp2.o: In function `~thread':
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:255: undefined reference to `boost::thread::detach()'
src\Cpp2.o: In function `ZN5boost6thread4joinEv':
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:751: undefined reference to `boost::thread::get_id() const'
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:751: undefined reference to `boost::this_thread::get_id()'
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:756: undefined reference to `boost::thread::join_noexcept()'
src\Cpp2.o: In function `~thread_data':
D:/tool/boost_1_54_0/boost/thread/detail/thread.hpp:91: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

P0W*_*P0W 5

-llibboost_thread-vc110-mt-1_54

应该

-lboost_thread-vc110-mt-1_54

boost_1.45使用以下命令行选项为我工作

-IC:\MinGW\boost_1_45_0 -LC:\MinGW\boost_1_45_0\stage\lib -lboost_thread-mgw46-mt-1_45