2

I added boost via this:

set(Boost_USE_STATIC_LIBS        ON) 
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP ${Boost_LIBRARIES})

And when I compiled source, I got:

demo.cpp:(.text+0x3d3): undefined reference to `boost::system::generic_category()'

I checked spelling (Boost_LIBRARIES vs BOOST_LIBRARIES) but it's ok.

I installed boost in Fedora with the package boost-devel.

rocambille
  • 15,398
  • 12
  • 50
  • 68
dev1223
  • 1,148
  • 13
  • 28

1 Answers1

7

Looking in the source code, Boost_LIBRARIES is filled according to the component list passed to find_package. Try:

find_package(Boost REQUIRED COMPONENTS system)

You should also use imported targets:

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost REQUIRED COMPONENTS system)

# the call to include_directories is now useless:
# the Boost::system imported target used below
# embeds the include directories

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP Boost::system)
rocambille
  • 15,398
  • 12
  • 50
  • 68
  • cmake fail to locate boost_system ... I have installed boost-system but boost-system-dev doesn't exists – dev1223 Sep 15 '16 at 14:27
  • 3
    just for others: the link syntax `Boost::` will automatically add the include directory to your target. That is why `include_directories` is "useless" here – Hayt Sep 15 '16 at 14:29
  • @Seraph to use the library you need the "-dev" version while building – Hayt Sep 15 '16 at 14:29
  • boost-system have no -dev version (or fedora doesn't have it ...) – dev1223 Sep 15 '16 at 14:30
  • After setting set(Boost_USE_STATIC_LIBS OFF) instead of ON, it works, but it uses shared lib right? So boost is not embedded in app ? – dev1223 Sep 15 '16 at 14:31
  • 1
    @Hayt you're right, less ambiguous with the explanation. I edited my answer – rocambille Sep 15 '16 at 14:35
  • 1
    @Seraph It seems that you need to install a package named [`boost-static`](http://koji.fedoraproject.org/koji/rpminfo?rpmID=7915998). – llonesmiz Sep 15 '16 at 17:37