2

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 :

  1. fix xcode/g++ so that it (also) use by default /usr/include
  2. force cmake to literally include /usr/include

I hope I have included enough information because it is my first question.

2 Answers 2

1

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}")
0

In XCode you should be able to add /usr/include to your search paths in your projects Build Settings:

XCode Search Paths

2
  • it's not quite comfortable to hack xcode project itself if you're using cmake as generator
    – user2288008
    Dec 10, 2013 at 11:21
  • @ruslo — op wrote "fix xcode/g++ so that it (also) use by default /usr/include" — which is my answer. Dec 10, 2013 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.