1

I have an undefined reference while trying to compile my Qt5 project. I am usually pretty confident with using CMake but this time I have a strange error that I can't figure out:

undefined reference to boost::system::generic_category()

/usr/local/include/boost/system/error_code.hpp:223: undefined reference to 'boost::system::generic_category()'

My configurations are:

  1. gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

  2. Qt5.15

  3. cmake version 3.16.3

  4. After typing whereis boost the outcome wasboost: /usr/include/boost and after applying the great power of dpkg -s libboost-dev | grep 'Version' :) the version is Version: 1.71.0.0ubuntu2

I don't understand what is happening, below an example of how my CMakeLists.txt is structured:

cmake_minimum_required (VERSION 3.1)
project(projectA)

set (OpenCV_DIR /home/to/opencv/build)
find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5Widgets)
find_package(Qt5PrintSupport)

#make them into headers
qt5_wrap_ui (UI_HDRS  ${UI})

add_executable(projectA main/main.cpp ui/qdarkstyle/style.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (projectA Qt5::Widgets  ${Boost_LIBRARIES} ${OpenCV_LIBS}  Qt5::PrintSupport)

add_library(projectA_lib SHARED ${SRCS} ${UI_HDRS})
target_include_directories (projectA_lib PUBLIC "src/" "ui/")
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries (projectA_lib Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS})

I have searched and applied solutions I saw on all possible sources I was able to find such as:

This source but that didn't work.

Also from here it seems that this solution shall be applied:

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)

However that also didn't do any specific benefits to finding the solution.

Other posts I consulted were this, this one but no answer was provided.

This post was useful but that also didn't provide any advice that didn't already know.

Thanks for pointing to the right direction and trying to find a solution.

Emanuele
  • 2,194
  • 6
  • 32
  • 71
  • `-lboost_system` should not be in `CMAKE_CXX_FLAGS`. – Some programmer dude May 20 '21 at 17:42
  • Please, show **complete error message**: It should include a library (executable) which is being built, paths, etc. Assuming you use `make` for build the project, run it with `VERBOSE=1` argument: that way **exact linker command line** will be printed. – Tsyvarev May 20 '21 at 17:43
  • And please do a verbose build (e.g. `make VERBOSE=1`) to see what commands are executed, complete with flags and options. – Some programmer dude May 20 '21 at 17:44
  • @Someprogrammerdude, yes I noticed but that was not the source of the error. I deleted it for completeness. Thanks for point that out though! – Emanuele May 20 '21 at 17:47
  • @Tsyvarev, I compile with `Qt5` debugger. How do I make a 'VERBOSE' build specifically? – Emanuele May 20 '21 at 17:49
  • When you say "Qt5 debugger" do you mean the [Qt Creator IDE](https://www.qt.io/product/development-tools)? – Some programmer dude May 20 '21 at 17:53
  • @Someprogrammerdude yes exactly – Emanuele May 20 '21 at 17:55
  • I don't know enough about Qt Creator to be able to tell, but you might try setting the `VERBOSE` environment variable (to e.g. `1`) before running `cmake` to generate the IDE project file. – Some programmer dude May 20 '21 at 18:24
  • 1
    Googling for "qt creator cmake verbose build" [gives](https://lists.qt-project.org/pipermail/qt-creator/2015-January/004356.html) Projects mode > Build > “Details” of Qbs build step > tick on “show command lines”. – Tsyvarev May 20 '21 at 18:31

0 Answers0