Reputation: 23
I am working on a macosx 10.9 with a fresh update of xcode and I have done xcode-select --install. I have a C++ file that use the header GL/glew.h and stdio.h
#include <stdio.h>
#include <GL/glew.h>
Glew is installed in /usr/include.
$ ls /usr/include/GL
glew.h glxew.h wglew.h
stdio.h is also in the /usr/include but a locate shows that it is present in many folders including :
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/usr/include/
If I try to compile the code without specifying the /usr/local include path, I get
fatal error: 'GL/glew.h' file not found
#include <GL/glew.h>
Notice that stdio seems to have been included successfully. If I add -I/usr/include to g++ in the command line the compilation is successful.
Now, I have a cMakeList.txt that add /usr/include, like that :
include_directories ( /usr/include/)
but in the resulting makefile the -I/usr/include/ does not appears and the compilation failed just as before.
My current workaround is a symbolic link to /usr/include/ named /usr/include2, and then include that directory. With that configuration the -I/usr/include2 is added to the makefile and everything works well. However it is ugly and I am missing something there.
My guess is that /usr/include should be included by default thus cmake skips it, however x-code use a different default include path (where incidentally stdio.h is also found).
Does anyone knows how to either :
I hope I have included enough information because it is my first question.
Upvotes: 2
Views: 4952
Reputation:
I'm not sure but I think cmake
or xcode
change their behaviour and now include directories automatically substitute from /usr/include/
to /.../Xcode.app/.../SDKs/MacOSX/usr/include
(it's working earlier for me). As a workaround you can add compiler flags explicitly:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include")
note that in your case you can use find_package
:
find_package(GLEW REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${GLEW_INCLUDE_DIRS}")
Upvotes: 1
Reputation: 774
In XCode you should be able to add /usr/include to your search paths in your projects Build Settings:
Upvotes: 0