Qt Creator没有通过CMake找到Boost,CMake本身没有

时间:2015-05-20 07:40:38

标签: boost cmake qt-creator

我有一个使用Boost和Qt的项目,并使用CMake编译。当我使用cmake … -DCMAKE_RELEASE_TYPE=Release -G ninja构建它并使用ninja构建它时,它可以正常工作。

要进行UI和调试,我想使用Qt Creator。当我用它打开CMake项目时,它找不到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".

顶级CMakeLists.txt如下所示:

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)

gui子目录中,我有另一个:

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)

这一切都在Kubuntu 15.04上运行。我不明白为什么当我从命令行调用它时,CMake可以找到Boost,但是当从Qt Creator调用它时无法找到Boost。我怎样才能在Qt Creator中使用它?

1 个答案:

答案 0 :(得分:2)

似乎CMake没有在/usr/lib/x86_64-linux-gnu查找库。调试输出显示它正在查看/usr/include/lib;/usr/include/../lib;/usr/include/../lib/;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib

如果您使用的是旧版本的CMake,可以通过升级来修复(我相信最近在FindBoost模块上完成了一些工作)。或者,您应该能够通过适当地设置BOOST_LIBRARYDIR来指示CMake查找正确的文件夹 - 即

cmake . -DBOOST_LIBRARYDIR=/usr/lib/x86_64-linux-gnu