Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator does not find Boost via CMake, CMake itself does

I have a project which uses Boost and Qt and is compiled using CMake. When I build it using cmake … -DCMAKE_RELEASE_TYPE=Release -G ninja and build it using ninja, it works just fine.

To to UI and debugging, I would like to use Qt Creator. When I open the CMake project with it, it cannot find Boost:

-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:529 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:531 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:533 ] Boost_USE_STATIC_LIBS = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:535 ] Boost_USE_STATIC_RUNTIME = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:537 ] Boost_ADDITIONAL_VERSIONS = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:539 ] Boost_NO_SYSTEM_PATHS = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:591 ] Declared as CMake or Environmental Variables:
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:593 ]   BOOST_ROOT = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:595 ]   BOOST_INCLUDEDIR = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:597 ]   BOOST_LIBRARYDIR = 
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:599 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:692 ] location of version.hpp: /usr/include/boost/version.hpp
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:716 ] version.hpp reveals boost 1.55.0
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:801 ] guessed _boost_COMPILER = -gcc49
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:811 ] _boost_MULTITHREADED = -mt
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:854 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:856 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:905 ] _boost_LIBRARY_SEARCH_DIRS = /usr/include/lib;/usr/include/../lib;/usr/include/../lib/;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1015 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-gcc49-mt-1_55;boost_filesystem-gcc49-mt;boost_filesystem-mt-1_55;boost_filesystem-mt;boost_filesystem
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1051 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-gcc49-mt-d-1_55;boost_filesystem-gcc49-mt-d;boost_filesystem-mt-d-1_55;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1015 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-gcc49-mt-1_55;boost_system-gcc49-mt;boost_system-mt-1_55;boost_system-mt;boost_system
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1051 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-gcc49-mt-d-1_55;boost_system-gcc49-mt-d;boost_system-mt-d-1_55;boost_system-mt-d;boost_system-mt;boost_system
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1015 ] Searching for SERIALIZATION_LIBRARY_RELEASE: boost_serialization-gcc49-mt-1_55;boost_serialization-gcc49-mt;boost_serialization-mt-1_55;boost_serialization-mt;boost_serialization
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1051 ] Searching for SERIALIZATION_LIBRARY_DEBUG: boost_serialization-gcc49-mt-d-1_55;boost_serialization-gcc49-mt-d;boost_serialization-mt-d-1_55;boost_serialization-mt-d;boost_serialization-mt;boost_serialization
-- [ /usr/share/cmake-3.0/Modules/FindBoost.cmake:1102 ] Boost_FOUND = 1
CMake Error at /usr/share/cmake-3.0/Modules/FindBoost.cmake:1199 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.55.0

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_filesystem
          boost_system
          boost_serialization

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Call Stack (most recent call first):
  CMakeLists.txt:17 (find_package)
-- Configuring incomplete, errors occurred!
See also "…/CMakeOutput.log".
See also "…/CMakeError.log".

The top level CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_CXX_COMPILER "/usr/bin/g++")
add_definitions("-march=native")
add_definitions("-std=c++11")
add_definitions("-Werror")
add_definitions("-Wall")
add_definitions("-fdiagnostics-color=always")

project(… CXX)

set(Boost_DEBUG ON)

find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem system serialization)
find_package(OpenMP)

if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

file(GLOB cpp_files *.cpp)

add_subdirectory(…)
add_subdirectory(gui)

And in the gui subdirectory I have another one:

cmake_minimum_required(VERSION 2.8.11)

project(…)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})

file(GLOB cpp_files *.cpp)
file(GLOB ui_files *.ui)

QT4_WRAP_UI(UIS_HDRS ${ui_files})

include_directories(${…_SOURCE_DIR})

add_executable(… ${UIS_HDRS} ${cpp_files})
target_link_libraries(… ${OpenCV_LIBS} Qt4::QtGui backend ${Boost_LIBRARIES})
install(TARGETS … DESTINATION bin)

This whole thing runs on Kubuntu 15.04. I do not understand why CMake can find Boost when I invoke it from the command line, but cannot find Boost when it is invoked from Qt Creator. How can I get this to work in Qt Creator as well?

like image 878
Martin Ueding Avatar asked Oct 31 '22 03:10

Martin Ueding


1 Answers

It seems CMake isn't looking in /usr/lib/x86_64-linux-gnu for the libraries. The debug output shows that it's looking in /usr/include/lib;/usr/include/../lib;/usr/include/../lib/;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib.

If you're using an older version of CMake, this may be fixed by upgrading (there has been some recent work done on the FindBoost module I believe). Alternatively, you should be able to direct CMake to look in the correct folder by setting BOOST_LIBRARYDIR appropriately - i.e.

cmake . -DBOOST_LIBRARYDIR=/usr/lib/x86_64-linux-gnu
like image 192
Fraser Avatar answered Dec 01 '22 06:12

Fraser