Now that I've looked through other peoples solutions for several hours and could not find quite the right answer for my problem I would like to bring my specific problem to you. :)
I am trying to build vsomeip with CMake. For that I previously built boost 1.55, however, I get the following errors in CMake:
The C compiler identification is MSVC 19.0.24215.1
The CXX compiler identification is MSVC 19.0.24215.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visua Studio 14.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.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: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Setting build type to 'RelWithDebInfo' as none was specified.
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindBoost.cmake:2025 (message):
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: C:/Program Files/boost/boost_1_55_0
Could not find the following static Boost libraries:
boost_system
boost_thread
boost_log
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, 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:99 (find_package)
Boost was not found!
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Systemd was not found, watchdog disabled!
using MSVC Compiler
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x00
Predefined routing application: vsomeipd
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
CMake Warning at CMakeLists.txt:335 (message):
Doxygen is not installed. Documentation can not be built.
CMake Warning at CMakeLists.txt:374 (message):
asciidoc is not installed. Readme can not be built.
GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
Configuring incomplete, errors occurred!
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles /CMakeOutput.log".
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles/CMakeError.log".
It cannot find the static Boost libraries. Now, I've tried playing around with the CMakeList.txt and here is the part of it that would be supposed to handle the linking:
# Boost
set(BOOST_INCLUDE_DIR C:/Program Files/Boost/boost_1_55_0)
set(BOOST_LIBRARYDIR C:/Program Files/Boost/boost_1_55_0/stage/libs)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
if(Boost_FOUND)
if(Boost_LIBRARY_DIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR not empty using it: ${Boost_LIBRARY_DIR}" )
else()
if(BOOST_LIBRARYDIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR empty but BOOST_LIBRARYDIR is set setting Boost_LIBRARY_DIR to: ${BOOST_LIBRARYDIR}" )
set(Boost_LIBRARY_DIR ${BOOST_LIBRARYDIR})
endif()
endif()
else()
MESSAGE( STATUS "Boost was not found!")
endif()
I have also tried using a newer boost version (1.67) with same results. Any help will be dearly appreciated!
Check if your compiled libraries are in the following directory:
C:/Program Files/Boost/boost_1_55_0/stage/libs
If not, set your lib folder directory path:
set(BOOST_LIBRARYDIR path_to_lib_directory)
As #Tsyvarev suggested I used set(Boost_DEBUG ON) to trace the exact locations and files that CMake was looking for and the discovered several problems:
1.) Setting the path to "C:/Program Files/Boost/boost_1_55_0"
causes problems, because of the space in the path
2.) It searched for the libraries covering multiple formats like: boost_thread-vc141-mt-gd-x32-1_55.lib.
However, when I built boost with incorrect parameters, so my libs were built like this:
libboost_thread-vc-mt-1_55.lib, which is not of the correct format.
3.) Unfortunately adding other options when building boost, e.g.:
b2 toolset=msvc-14.1 address-model=32 --build-type=complete
caused other errors. Also building boost_1_67_0 manually worked for me at all.
My solution to the problem was to simply take one of the third-party download( https://dl.bintray.com/boostorg/release/1.67.0/binaries/). This way all the libraries were built correctly and I had no trouble linking to them.
Related
So I'm trying to get my cmake to work with conan/boost. For this I have a simple conan file:
from conans import ConanFile
class Boost_Conan_Cmake_MinimalConfig(ConanFile):
name = "Boost_Conan_Cmake_MinimalConfig"
generators = "cmake"
options = {"shared": [True, False], "st": [True, False]}
default_options = {"shared": False, "st": True}
def requirements(self):
self.requires("boost/1.69.0#_/_")
self.options["boost"].shared = False
I call this via conan install . --build=missing. This runs perfectly fine and installs boost without problems. When investigating into the folder you can also find all the boost libraries etc.
Next comes my CMakeList.txt. It's pretty straight forward:
cmake_minimum_required(VERSION 3.0)
# CHANGE PROJECT NAME, SOURCES AND DEPENDANT TARGETS
project(boost-conan CXX)
include(conanbuildinfo.cmake)
conan_basic_setup()
set(TARGET_NAME ${PROJECT_NAME})
set(${TARGET_NAME}_SRC src/main.cpp)
find_package(Boost 1.69.0 REQUIRED COMPONENTS filesystem)
add_executable(test "src/main.cpp")
target_include_directories(test PUBLIC $(Boost_INCLUDE_DIRS))
target_link_libraries(test Boost::filesystem)
However, when I try to run this CMake file I get an error:
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- The CXX compiler identification is MSVC 19.26.28805.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: D:/boost-conan
-- WARN: CONAN_COMPILER variable not set, please make sure yourself that your compiler and version
matches your declared settings
CMake Error at C:/Program Files/CMake/share/cmake-
3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find Boost (missing: filesystem) (found suitable version
"1.69.0", minimum required is "1.69.0")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393(_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.16/Modules/FindBoost.cmake:2179 (find_package_handle_standard_args)
CMakeLists.txt:11 (find_package)
-- Configuring incomplete, errors occurred!
See also "D:/boost-conan/CMakeFiles/CMakeOutput.log".
Does anyone have an idea how to fix this? Or does anyone have an idea why this error occurs? The Error message alone doesn't really help...
Thanks in advance!
I am following the instructions from https://badprog.com/c-boost-setting-up-on-windows-10 . I have Visual Studio 2017 installed, and installed boost_1_71_0-msvc-14.1-64.exe. CMake was downloaded from cmake.org/download/, cmake-3.19.0-rc1-win64-x64.msi.
I have a project that needs Boost Beast, which I believe is 1.70 or higher.
When I run cmake . everything seems fine:
C:\Users\Public\xyz>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The CXX compiler identification is MSVC 19.24.28314.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
-- Found Boost: C:/local/boost_1_71_0 (found suitable version "1.71.0", minimum required is "1.70") found components: thread system chrono date_time atomic
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Public/xyz
The resulting project opens in Visual Studio 2017, but then complains it needs the 2019 build tools. Surprisingly, as you can see above, it's building for Visual Studio 2019?
But, after killing CMakeCache.txt and CMakeFiles, if I do this:
C:\Users\Public\xyz>cmake -G "Visual Studio 15 2017" .
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The CXX compiler identification is MSVC 19.16.27034.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: thread system) (found suitable version
"1.71.0", minimum required is "1.70")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:577 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.19/Modules/FindBoost.cmake:2176 (find_package_handle_standard_args)
CMakeLists.txt:29 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Public/xyz/CMakeFiles/CMakeOutput.log".
Suddenly it can't find Boost components (but can find Boost?). I've tried various forms of -DBOOST_LIBRARYDIR or -DBOOST_ROOT, etc., to no avail, but I don't seem to have the usual stackoverflow problem of cmake not being able to find Boost; instead it doesn't seem to recognize the Visual Studio 2017 target, despite having been installed for msvc-14.1?
CMakeLists.txt:
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.1)
# Force C++11, for Boost Beast (async http library)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Project's name
project(xyz
VERSION 0.1
LANGUAGES CXX)
# Set the output folder where the program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# Specify .cpp and .hpp is in src/
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
include_directories("${PROJECT_SOURCE_DIR}")
# Add source to build target for hello world...
add_executable(main ${PROJECT_SOURCE_DIR}/main.cpp)
# Testing http support
ADD_EXECUTABLE( server ${PROJECT_SOURCE_DIR}/server.cpp )
FIND_PACKAGE( Boost 1.70 REQUIRED COMPONENTS thread system )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
target_link_libraries ( server LINK_PUBLIC ${Boost_LIBRARIES} )
In the end, the issue was simple. If I may so, it was an easy mistake for a beginner to make but almost impossible for a beginner to unravel with regular google searching.
When I issued cmake ., it was defaulting to a 64 bit build, but assuming a Visual Studio 2019 target. That was wrong.
The equivalent should have been cmake -G "Visual Studio 15 2017 Win64" . But not knowing this, and following the wrong tutorials, I was issuing instead cmake -G "Visual Studio 15 2017" .. This defaulted to a 32 bit build - though by default it never mentions this fact. It could find boost, but all library files were for 64 bit and useless for 32 bit, so it simply said "I can't find anything!".
My thanks to #Tsyvarev, who should get the credit for the answer. Turning on DEBUG and looking at searched library files character by character was indeed the right call.
I have the following CMakeLists.txt:
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 ()
When I run cmake, I get the foloowing output:
> "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".
If I use this CMakeLists.txt in Clion, the system is able to find the Boost libraries. Following are the entries in CMakeCache.txt that I get from 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
But when I run cmake separately from the commandline, I get the following in 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
AIM: Get the MySQL and Boost include files and libraries paths correct when building C++ project using cmake
How do I set my env. correctly so that cmake is able to find all the required include file and libraries?
Maybe you have no F:/MinGW/bin in your PATH variable?
Also, which MinGW distro you use? I would recommend you this one http://www.msys2.org/. It has very handy package manager.
You just do
pacman -S mingw-w64-x86_64-boost
and CMake finds boost without any special environment configuration.
I'm very new to CMake, and I try to write a CMake file for my project.
My project consists of .h and .cpp files, generating an executable, and using the SFML library.
I've installed the findSFML script, I use the find_package function of CMake:
cmake_minimum_required(VERSION 2.6)
# Projet name
project("Witch_Blast")
file(
GLOB_RECURSE
source_files
src/*
)
add_executable(
"Witch_Blast"
${source_files}
)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.1 REQUIRED system window graphics audio)
target_link_libraries(Witch_Blast ${SFML_LIBRARIES})
I try to generate a Windows Code::Blocks project.
It finds the library and generate projects files.
My problem:
It won't compile because it won't find the SFML header files, and I cannot modify the project setting...
What have I done wrong ?
Thanks !
EDIT:
CMake generation output:
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found SFML 2.1 in C:/Lib/SFML-2.1_TDM/include
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Seb/Dev/Witch Blast/cmakedir
message(SFML_LIBRARIES):
debugC:/Lib/SFML-2.1_TDM/lib/libsfml-system-d.aoptimizedC:/Lib/SFML-2.1_TDM/lib/
libsfml-system.adebugC:/Lib/SFML-2.1_TDM/lib/libsfml-window-d.aoptimizedC:/Lib/S
FML-2.1_TDM/lib/libsfml-window.adebugC:/Lib/SFML-2.1_TDM/lib/libsfml-graphics-d.
aoptimizedC:/Lib/SFML-2.1_TDM/lib/libsfml-graphics.adebugC:/Lib/SFML-2.1_TDM/lib
/libsfml-audio-d.aoptimizedC:/Lib/SFML-2.1_TDM/lib/libsfml-audio.a
(But it's not a linker error, it's an include path error)
You need to add the header directory to you compiler's path.
include_directories(${SFML_INCLUDE_DIR})
All variables find_package(SFML) sets can be found here.
I have compiled Boost 1.51.0 on Windows using the rubenvb's CLang build. I actually compiled b2 using MinGW:
bootstrap mingw
... compiling b2 using mingw...
and then I compiled the libraries with CLang:
b2 toolset=clang stage --stagedir=. --build-type=complete --with-regex ...
By the way, even if I specified --build-type=complete there are no DLLs in lib directory, but I read somewhere that CLang has still problem with linking on Windows so that might be the reason. Anyway static libraries are fine for me. I got these files in %BOOST_ROOT%\lib:
libboost_regex-clang31-1_51.lib
libboost_regex-clang31-d-1_51.lib
libboost_regex-clang31-mt-1_51.lib
libboost_regex-clang31-mt-d-1_51.lib
libboost_regex-clang31-mt-s-1_51.lib
libboost_regex-clang31-mt-sd-1_51.lib
libboost_regex-clang31-s-1_51.lib
libboost_regex-clang31-sd-1_51.lib
Now, if I compile something with CLang from command line everything works. The problem shows when I try to make CMake find Boost libraries: it simply could not find them. I tried with this CMakeFiles.txt:
cmake_minimum_required (VERSION 2.8)
project(ccc)
# Setting/unsetting this does not change anything.
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS regex REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(ccc main.cpp)
target_link_libraries(ccc
${Boost_REGEX_LIBRARY}
)
Building it using MinGW (and a MinGW compiled version of Boost) it works. If I try with CLang (after having setted CC=clang, CXX=clang++ and BOOST_ROOT=C:/misc/boost/clang-1_51_0) it does not:
D:\Desktop\ppp>cmake -G "MinGW Makefiles" ..\ccc
-- The C compiler identification is Clang 3.1.0
-- The CXX compiler identification is Clang 3.1.0
-- Check for working C compiler: C:/misc/clang/bin/clang.exe
-- Check for working C compiler: C:/misc/clang/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
Unable to find the requested Boost libraries.
Boost version: 1.51.0
Boost include path: C:/misc/boost/clang-1_51_0
The following Boost libraries could not be found:
boost_regex
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:5 (find_package)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_REGEX_LIBRARY (ADVANCED)
linked by target "ccc" in directory D:/Desktop/ccc
-- Configuring incomplete, errors occurred!
However, if I compile manually it works again:
clang++ main.cpp -I%BOOST_ROOT% -L%BOOST_ROOT%\lib -llibboost_regex-clang31-1_51
...Ok, and the executable works
Manually setting BOOST_LIBRARYDIR does not work either. Neither does using backslashes \.
Looking inside the file "C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake" you can find a list of all the variables related to Boost you can use. The one you need is Boost_COMPILER (Boost_DETAILED_FAILURE_MSG can also be useful to diagnose problems):
# Boost_COMPILER Set this to the compiler suffix used by Boost
# (e.g. "-gcc43") if FindBoost has problems finding
# the proper Boost installation