Reputation: 197
I am trying to compile a c++ project with clang++ and the CXX_FLAGS "-Wall -stdlib=libc++ -std=c++11" on OS X. The project is a CMAKE project and requires cln and ginac to be included. However the compiler cannot find the according headers, when I give include statements like this:
#include <cln/cln.h>
or
#include <ginac/ginac.h>
although both libraries are installed in /usr/local/lib and their include directories (/usr/local/include/cln and /usr/local/include/ginac) exist. I've tried
set(CMAKE_INCLUDE_PATH /usr/local/include/cln:/usr/local/include/ginac )
but it does not show any effect, the error message stays the same:
fatal error: 'ginac/ginac.h' file not found
#include <ginac/ginac.h>
^
Update:
I managed to add compiler flags for verbose, which shows me, that the paths, where clang searches for the required headers are wrong, so the problem seems to resemble down to the question how to change these paths:
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
whereas the required headers are still in /usr/local/include.
Update 2 Adding the CXX_FLAG
-I/usr/local/include
solves the problem - Where can I globally set this as a default?
Upvotes: 1
Views: 1841
Reputation: 39
I just want to add to the discussion that I encountered almost the same issue as the author, where include_directories("/usr/local/include/something")
in a CMakeLists.txt
file did not work, however I was able to get around the problem using the approach recommended by adding a specific compiler flag to the CMakeLists.txt
file:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include/something")
Could this be a bug in cmake? This issue is only tangentially related, but may be of use to anyone attempting to get to the bottom of this: https://gitlab.kitware.com/cmake/cmake/issues/19120
Upvotes: 1
Reputation: 409374
You're specifying the full paths in the CMakeFile.txt
, including the subdirectory. So that means when you include e.g. <cln/cln.h>
the preprocessor will look for /usr/local/include/cln/cln/cln.h
.
Try instead e.g.
set(CMAKE_INCLUDE_PATH /usr/local/include)
Upvotes: 0