0

我以前已经配置过boost,但是这次我不知道是什么导致了问题。我提供了一些屏幕截图,显示了我在 CodeBlocks (svn7550) 中的设置。我使用这些命令构建了我的 Boost 库。

Boost被提取到F:\主文件夹地址为:

F:\boost_1_49_0

以下是命令:

F:\
F:\ cd Boost_1_44_0
F:\ Boost_1_44_0> bootstrap.bat
F:\ Boost_1_44_0>bjam toolset=gcc --build-type=complete stage

上面没有做任何好事,所以我写了这个并且实际上编译得很好:

F:\ Boost_1_44_0>bjam variant=debug,release link=static address-model=32 

进而

F:\boost_1_49_0>bjam toolset=gcc variant=debug,release link=static threading=multi address-model=32 --build-type=complete stage

然后当我尝试编译一个线程示例时:

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

void wait(int seconds)
{
  boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}

boost::mutex mutex;

void thread()
{
  for (int i = 0; i < 5; ++i)
  {
    wait(1);
    mutex.lock();
    std::cout << "Thread " << boost::this_thread::get_id() << ": " << i << std::endl;
    mutex.unlock();
  }
}

int main()
{
  boost::thread t1(thread);
  boost::thread t2(thread);
  t1.join();
  t2.join();
}

它因以下错误而失败:

||=== Boost Example, Debug ===|
obj\Debug\main.o||In function `Z6threadv':|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|18|undefined reference to `_imp___ZN5boost11this_thread6get_idEv'|
obj\Debug\main.o||In function `main':|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|27|undefined reference to `_imp___ZN5boost6thread4joinEv'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6thread4joinEv'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
F:\boost_1_49_0\boost\thread\win32\thread_data.hpp|161|undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'|
obj\Debug\main.o||In function `thread<void (*)()>':|
F:\boost_1_49_0\boost\thread\detail\thread.hpp|205|undefined reference to `_imp___ZN5boost6thread12start_threadEv'|
||=== Build finished: 9 errors, 0 warnings (0 minutes, 58 seconds) ===|

虽然上面的线程示例失败了,但这段代码编译得很好:

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

这些是我目前的 CB 截图:

http://upload.ustmb.ir/uploads/13336039464.jpg

http://upload.ustmb.ir/uploads/13336039463.jpg

http://upload.ustmb.ir/uploads/13336039462.jpg

http://upload.ustmb.ir/uploads/13336039465.jpg

这是我的 stage/lib 文件夹的内容:

http://upload.ustmb.ir/uploads/13335642651.jpg

有人能告诉我问题是什么吗?

4

1 回答 1

4

我使用这个命令来编译 boost:

F:\
F:\ cd Boost_1_44_0
F:\ Boost_1_44_0> bootstrap.bat
F:\ Boost_1_44_0>bjam toolset=gcc --build-type=complete stage variant=debug,release threading=multi link=static 

其余配置相同。我只是按照这里的指南 并添加了:

#define BOOST_THREAD_USE_LIB

到我的源代码的第一行,错误就消失了。

于 2012-04-05T20:58:00.110 回答