Undefined reference to 'boost::system::generic_category()'?

前端 未结 4 1900
执笔经年
执笔经年 2020-12-10 16:23

it seems that i am unable to see the obvious. I wanted to use some Boost library features for my project and know i am getting these nice errors all of a sudden:

相关标签:
4条回答
  • 2020-12-10 16:38

    Ok, for those interested, the answer of Mark Garcia was a good call but what's more important here is that you need to explicitly link the libs you want from boost like

    TARGET_LINK_LIBRARIES(ATFOR ${OpenCV_LIBS} curl ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})

    All other options i tried and read about didn't work me, don't know why but i hope this helps someone.

    0 讨论(0)
  • 2020-12-10 16:45

    Check if you have the correct build (gcc, msvc...) of your boost libraries. I had this error when I tried linking a project using mingw with libraries built for msvc. If it is different, try building it for the platform you are using in your project.

    The first time I used Boost I built it with default parameters resulting in libraries built for msvc, even though I was using mingw for my project. However CMake did find headers and libraries and everything seemed ok until I started using library features and compiling, that resulted in error mentioned by OP.

    Rebuilding boost to toolset=gcc solved it (I was using Windows, CMake + MinGW).

    0 讨论(0)
  • 2020-12-10 16:47

    The "system" lib is missing in the linking stage. My config is as follows and it fixes the error:

    find_package(Boost 1.55.0 REQUIRED COMPONENTS system filesystem)
    
    include_directories(... ${Boost_INCLUDE_DIRS})
    
    link_directories(... ${Boost_LIBRARY_DIRS})
    
    target_link_libraries(... ${Boost_LIBRARIES})
    

    Note that using only

    find_package(Boost 1.55.0 REQUIRED)
    

    does not work as ${Boost_LIBRARIES} won't be available then.

    0 讨论(0)
  • 2020-12-10 17:02

    You must explicitly add the system library for it to be linked into your program

    find_package(Boost REQUIRED COMPONENTS system)
    #                                      ^^^^^^ this :)
    

    This must also be done for other Boost libraries that are built separately (regex, thread, etc.) (see here).

    0 讨论(0)
提交回复
热议问题