使用boost threads教程未定义引用`_gmtime32'

时间:2013-06-03 16:38:36

标签: c++ gcc boost mingw boost-thread

我正在关注boost线程的初学者教程: http://www.codeproject.com/Articles/279053/How-to-get-started-using-Boost-threads

他们提供的这个样本一切都很顺利:

#define BOOST_THREAD_USE_LIB

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

void workerFunc()
{
    boost::posix_time::seconds workTime(3);
    std::cout << "Worker: running" << std::endl;

    // Pretend to do something useful...
    boost::this_thread::sleep(workTime);
    std::cout << "Worker: finished" << std::endl;
}

int main(int argc, char* argv[])
{
    std::cout << "main: startup" << std::endl;
    boost::thread workerThread(workerFunc);

    std::cout << "main: waiting for thread" << std::endl;
    workerThread.join();

    std::cout << "main: done" << std::endl;
    return 0;
}

但后来我决定尝试没有睡眠功能。所以我评论了这些内容。

#define BOOST_THREAD_USE_LIB

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

void workerFunc()
{
    //boost::posix_time::seconds workTime(3);
    std::cout << "Worker: running" << std::endl;

    // Pretend to do something useful...
    //boost::this_thread::sleep(workTime);
    std::cout << "Worker: finished" << std::endl;
}

int main(int argc, char* argv[])
{
    std::cout << "main: startup" << std::endl;
    boost::thread workerThread(workerFunc);

    std::cout << "main: waiting for thread" << std::endl;
    workerThread.join();

    std::cout << "main: done" << std::endl;
    return 0;
}

我开始收到以下编译错误:

  

)] + 0x40)||未定义对`_gmtime32'|

的引用

我已经做了很多窥探试图找出这意味着什么以及为什么只有当我删除这两行时才会发生这种情况。截至目前,我倾向于使用某种类型的标题,例如time.h,我必须包括(虽然我已经尝试过了)。

我正在使用一个相当奇怪的设置。 Code ::具有mingw / gcc的块。我在codeblocks教程后面用命令行参数编译了boost库: http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef

这一切看起来都很好用,但我想我可能错误地构建了库。

我会深入挖掘,但错误的文件名不是标准的,并列为“)] + 0x40)”。我不确定这意味着什么 - 它可能是某种文件位置地址吗?

更多信息:

Windows XP 32 bit
CodeBlocks 10.05
MingW GCC 4.4.3
Boost 1_53_0

建立日志:

  

链接控制台可执行文件:bin \ Debug \ Bjarne_Strousup_Samples.exe   .... \代码块\ LIB \ libboost_thread-mgw44-MT-1_53.a(thread.o):thread.cpp :(文字$ _ZN5boost9date_time6c_time6gmtimeEPKlP2tm [提振:: DATE_TIME :: c_time :: gmtime的(长   const *,tm *)] + 0x40):未定义引用`_gmtime32'colle2:ld   返回1退出状态进程终止,状态为1(0分钟,6   秒)1个错误,0个警告

命令行尝试:

C:\CodeBlocks Tests\BoostExamples>g++ main.cpp -lboost_thread -lboost_system -lb
oost_chrono
main.cpp:5:28: error: boost/thread.hpp: No such file or directory
main.cpp:6:31: error: boost/date_time.hpp: No such file or directory
main.cpp: In function 'int main()':
main.cpp:21: error: 'boost' has not been declared
main.cpp:21: error: expected ';' before 'workerThread'
main.cpp:24: error: 'workerThread' was not declared in this scope

C:\CodeBlocks Tests\BoostExamples>

LINKER SETTINGS: Linker Settings

IDM链接: http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.basetechref%2Fdoc%2Fbasetrf1%2Fctime.htm

我认为错误发生在c_time.hpp的这一行:

  static std::tm* gmtime(const std::time_t* t, std::tm* result)

0 个答案:

没有答案