This question is very similar to Why is this boost header file not included, however the hints there don't (seem to) solve my problem.
I got a CMakeLists.txt
CMAKE_MINIMUM_REQUI开发者_高级运维RED(VERSION 2.8)
PROJECT(jetorigin)
SET(Boost_ADDITIONAL_VERSIONS "1.43" "1.43.0" "1.44" "1.44.0" "1.45" "1.45.0")
SET(BOOST_ROOT "$ENV{HOME}/usr")
MESSAGE(STATUS "** Search Boost root: ${BOOST_ROOT}")
FIND_PACKAGE(Boost 1.43 COMPONENTS filesystem regex REQUIRED)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARY_DIRS}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ADD_SUBDIRECTORY(src)
And include some boost headers in my code like this:
#include <boost/regex.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
Now the output from cmake looks ok
-- ** Search Boost root: /home/oli/usr
-- Boost version: 1.43.0
-- Found the following Boost libraries:
-- filesystem
-- regex
-- ** Boost Include: /home/oli/usr/include
-- ** Boost Libraries: /home/oli/usr/lib
-- ** Boost Libraries: /home/oli/usr/lib/libboost_filesystem.so;/home/oli/usr/lib/libboost_regex.so
But I get this error:
error: boost/regex.hpp: No such file or directory
(and similar for the other includes). Full output from make VERBOSE=1 can be found here http://pastebin.ca/2039425. It looks as though there is no -I flag added even though Boost_INCLUDE_DIR seems to be set correctly.
I'm using CMake 2.8.1 by the way. I would very much appreciate any hints on what is going wrong here..
EDIT: I've found the problem. Seems I pulled some ancient version of my standard CMakeLists.txt from the depths of my archives. It needs to be:
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
(note the non-capitalized "Boost")... Maybe older versions of CMake have been more tolerant in this respect or by bad luck I simply chose to start with a version of my CMakeLists.txt with an unfixed bug..
Since you did not specify a mode for find_package
, it attempts to first use MODULE
mode, and then CONFIG
mode. As per the docs for the FindBoost
module, the cache variable storing the directory containing Boost headers is named Boost_INCLUDE_DIR
and not BOOST_INCLUDE_DIR
. As per the CMake language docs' section on variables, CMake variable names are case-sensitive. I don't know why you had another CMakeLists.txt file with BOOST_INCLUDE_DIR
working.
精彩评论