链接到Boost系统的错误

时间:2015-09-20 02:40:21

标签: c++ boost linker mingw

我为MinGW 4.9.2 32位制作了Boost 1.59,如下所示:

  1. bootstrap.bat mingw
  2. b2 --prefix=%USERPROFILE%\Code\Libraries\boost toolset=gcc install(这些是静态库)
  3. 尝试编译时:

    #include <iostream>
    #include <boost/asio.hpp>
    #include <boost/date_time/posix_time/posix_time.hpp>
    
    using namespace std;
    
    int main()
    {
        boost::asio::io_service io;
        boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
        t.wait();
        cout << "Hello World!" << endl;
        return 0;
    }
    

    使用:

    g++ -o test -L %USERPROFILE%\Code\Libraries\boost\lib -l boost_system-mgw49-mt-1_59 -I %USERPROFILE%\Code\Libraries\boost\include\boost-1_59 main.cpp
    

    我收到此错误:

    C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x193): undefined reference to `boost::system::generic_category()'
    C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x19d): undefined reference to `boost::system::generic_category()'
    C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x1a7): undefined reference to `boost::system::system_category()'
    C:/Program Files (x86)/QT/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o: bad reloc address 0xe in section `.text$_ZN5boost6system14error_categoryD2Ev[__ZN5boost6system14error_categoryD2Ev]'
    collect2.exe: error: ld returned 1 exit status
    

    我在两台计算机上遇到同样的错误。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

这是一个链接器错误。您需要链接到Boost系统库。

这样做

g++ -o test -L %USERPROFILE%\Code\Libraries\boost\lib -lboost_system -I %USERPROFILE%\Code\Libraries\boost\include\boost-1_59 main.cpp