在使用代码块配置boost时遇到问题

时间:2012-04-05 04:29:29

标签: c++ boost configuration compiler-errors codeblocks

我以前曾经配置过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 screenShots:

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

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

1 个答案:

答案 0 :(得分: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 

其余的配置都是一样的。我刚跟着the guide here 并添加了:

#define BOOST_THREAD_USE_LIB

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