2017-06-18 87 views
1

我有以下CMakeLists.txt找不到MySQL和升壓包括在窗口從cmake的/庫

cmake_minimum_required(VERSION 3.7) 
project(TestProject) 
message(STATUS "start running cmake...") 
find_package(Boost 1.61.0 COMPONENTS system filesystem REQUIRED) 
set(SOURCE_FILES main.cpp) 
add_executable(TestProject ${SOURCE_FILES}) 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 
include_directories(TestProject $ENV{MYSQL_INCLUDE_DIR}) 
target_link_libraries(TestProject $ENV{MYSQL_LIBRARIES}) 
if (Boost_FOUND) 
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}") 
    message(STATUS "Boost_VERSION: ${Boost_VERSION}") 
    include_directories(TestProject ${Boost_INCLUDE_DIRS}) 
    target_link_libraries(TestProject ${Boost_LIBRARIES}) 
endif() 

當我運行cmake,我得到foloowing輸出:

> "E:\JetBrains\CLion 2017.1.1\bin\cmake\bin\cmake.exe" -DCMAKE_CXX_COMPILER="F:/MinGW/bin/g++.exe" -DCMAKE_C_COMPILER="F:/MinGW/bin/gcc.exe" -G "MinGW Makefiles" .. 
-- The C compiler identification is GNU 6.1.0 
-- The CXX compiler identification is GNU 6.1.0 
-- Check for working C compiler: F:/MinGW/bin/gcc.exe 
-- Check for working C compiler: F:/MinGW/bin/gcc.exe -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Check for working CXX compiler: F:/MinGW/bin/g++.exe 
-- Check for working CXX compiler: F:/MinGW/bin/g++.exe -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- start running cmake... 
CMake Warning at E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message): 
    Imported targets not available for Boost version 
Call Stack (most recent call first): 
    E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES) 
    E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES) 
    CMakeLists.txt:6 (find_package) 


CMake Warning at E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message): 
    Imported targets not available for Boost version 
Call Stack (most recent call first): 
    E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES) 
    E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES) 
    CMakeLists.txt:6 (find_package) 


CMake Error at E:/JetBrains/CLion 2017.1.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1793 (message): 
    Unable to find the requested Boost libraries. 

    Unable to find the Boost header files. Please set BOOST_ROOT to the root 
    directory containing Boost or BOOST_INCLUDEDIR to the directory containing 
    Boost's headers. 
Call Stack (most recent call first): 
    CMakeLists.txt:6 (find_package) 


-- Path to MySQL include directories: E:\MySQL\MySQL Connector C++ 1.1.9\include 
-- Path to MySQL library directories: E:\MySQL\MySQL Connector C++ 1.1.9\lib\opt\mysqlcppconn.lib 
-- Configuring incomplete, errors occurred! 
See also "F:/Ubuntu_Backup/CPPs/build/CMakeFiles/CMakeOutput.log". 

如果我用這個CMakeLists.txtClion中,系統能夠找到Boost庫。以下是條目CMakeCache.txt,我從CLion

//The directory containing a CMake configuration file for Boost. 
Boost_DIR:PATH=Boost_DIR-NOTFOUND 

//Boost filesystem library (debug) 
Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=F:/MinGW/lib/libboost_filesystem.a 

//Boost filesystem library (release) 
Boost_FILESYSTEM_LIBRARY_RELEASE:FILEPATH=F:/MinGW/lib/libboost_filesystem.a 

//Path to a file. 
Boost_INCLUDE_DIR:PATH=F:/MinGW/include 

//Boost library directory DEBUG 
Boost_LIBRARY_DIR_DEBUG:PATH=F:/MinGW/lib 

//Boost library directory RELEASE 
Boost_LIBRARY_DIR_RELEASE:PATH=F:/MinGW/lib 

//Boost system library (debug) 
Boost_SYSTEM_LIBRARY_DEBUG:FILEPATH=F:/MinGW/lib/libboost_system.a 

//Boost system library (release) 
Boost_SYSTEM_LIBRARY_RELEASE:FILEPATH=F:/MinGW/lib/libboost_system.a 

得到但當我從命令行單獨運行cmake,我得到CMakeCache.txt如下:

//The directory containing a CMake configuration file for Boost. 
Boost_DIR:PATH=Boost_DIR-NOTFOUND 

//Boost filesystem library (debug) 
Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=Boost_FILESYSTEM_LIBRARY_DEBUG-NOTFOUND 

//Boost filesystem library (release) 
Boost_FILESYSTEM_LIBRARY_RELEASE:FILEPATH=Boost_FILESYSTEM_LIBRARY_RELEASE-NOTFOUND 

//Path to a file. 
Boost_INCLUDE_DIR:PATH=Boost_INCLUDE_DIR-NOTFOUND 

//Boost system library (debug) 
Boost_SYSTEM_LIBRARY_DEBUG:FILEPATH=Boost_SYSTEM_LIBRARY_DEBUG-NOTFOUND 

//Boost system library (release) 
Boost_SYSTEM_LIBRARY_RELEASE:FILEPATH=Boost_SYSTEM_LIBRARY_RELEASE-NOTFOUND 

目的:獲得MySQL和升壓包括文件和庫路徑在構建C++項目時使用正確cmake

如何設置我的環境。正確,以便cmake能夠找到所有必需的包含文件和庫?

回答

0

也許你在PATH變量中沒有F:/ MinGW/bin? 另外,您使用哪種MinGW發行版?我會建議你這一個http://www.msys2.org/。它有非常方便的包管理器。 你只是做

pacman -S mingw-w64-x86_64-boost 

和CMake發現提升沒有任何特殊的環境配置。