3

As a follow up to another question I recently asked, I realize my issue is that I don't know how to include Apple 'frameworks' in the Eclipse CDT project properties so that they're picked up and linked at compile time.

This results in includes in this form not to be resolved:

#include <OpenCL/cl.h>

Where the actual path would be something like:

/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers

And the cmd line option would be (if I was manually compiling):

-framework OpenCL

In summary: How can I get Eclipse to see the framework(s) I want fromt he project properties?

Any help highly appreciated!

Community
  • 1
  • 1
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
  • Can you edit the toolchain and add the framework header and lib directories? – trojanfoe Nov 09 '11 at 15:45
  • I am a total noob with eclipse cdt - how do I do that? I see a Tool Chain Editor in the proj properties but I fail to see how I can add that stuff from there – JohnIdol Nov 09 '11 at 15:57
  • Try Project Properties > C/C++ General > Paths and Symbols. – trojanfoe Nov 09 '11 at 16:44
  • Yeah I can add the path to the headers via 'paths and symbols' (specifying the full path) but it does not address the 'framework' thing (its specific to the way OSX handles frameworks) so it still cannot resolve symbols etc when you #include – JohnIdol Nov 09 '11 at 17:09
  • Hmmm, if you are using the Apple toolchain then there is a `-iframework` option to the compiler; does it help if you set this? – trojanfoe Nov 09 '11 at 17:32
  • I guess it would help, I am afraid I dont know where to set that from the project properties in eclipse :) – JohnIdol Nov 09 '11 at 18:02
  • It'll be in the Project Properties > C/C++ General area somewhere. – trojanfoe Nov 09 '11 at 18:18

4 Answers4

8

An alternative answer to JohnIdol's answer. In particular, an approach that can work in the case that you don't want to change the <OpenCL/cl.h> reference to <cl.h>

First, I came to the site with exactly this question in mind (how to include Apple 'frameworks' in Eclipse CDT (C/C++) projects) and I really appreciate the discussion - it gave me a starting point.

John's answer is cool but it does involve changing how the include file is called (e.g., <OpenCL/cl.h> becomes <cl.h> in the code). Then he does a direct include-path reference in the eclipse properties for each Header directory he needs.

In my case, I had checked-out GNU Backgammon to play around with the source code. This code compiles (with some mods to LDFLAGS and CPPFLAGS before doing the autogen.sh) on the OS X CLI environment using the I-guess-standard apple approach of the -framework option and with include files references like #include <CoreAudio/CoreAudioTypes.h>

I may never actually commit anything but I didn't want to start hacking the #includes in code that is already compiling just fine using the standard approach. So I did the following:

  1. Made a new directory in my workspace gnubg called "Frameworks".
  2. Inside that directory, make soft-links to the header directories.

    ln -s /System/Library/Frameworks/CoreAudio.framework/Headers CoreAudio
    
  3. In the gnubg project properties > C/C++ General> Paths and Symbols, added /gnubg/Frameworks to the Include directories (as a workspace path). I only had to do this once, regardless of the number of soft links I made.

This way I did not have to change the code at all, Eclipse was happy, CLI compilation was happy as well.

I note that there is a slight wrinkle if using some directories in Frameworks such as the CoreServices.framework. In those cases there is a Frameworks subdirectory and relative path references in some of the include files (e.g., ..) to other include files. So in this case I had to modify the procedure a bit. Basically, I had to add an additional sub-directory in Frameworks for CoreServices.framework and then in that directory I had to add two soft links. One for the CoreServices (for the Headers) and one for Framework subdirectory.

lrwxr-xr-x  1 dhansen  staff    57B Jul 27 02:06 CoreServices -> /System/Library/Frameworks/CoreServices.framework/Headers
lrwxr-xr-x  1 dhansen  staff    60B Jul 27 02:05 Frameworks -> /System/Library/Frameworks/CoreServices.framework/Frameworks

Then I had to add /gnubg/Frameworks/CoreServices.framework to the include path (step 3 above).
And that's it. No more include file problems.

danhan
  • 96
  • 1
  • 3
1

Since current Eclipse CDT releases don't perform sub-framework header inclusion correctly, you can avoid sub-framework problems (like those generated by the CoreServices header files) by creating symbolic links to the include directories of each sub-framework. I elaborated on this subject, which stems from danhan answer, in the following post:

http://thegreyblog.blogspot.com/2014/02/how-to-include-apple-frameworks-headers.html

In order to automate this process, I've created a Z shell script which automates this process and creates the symlink to the specified frameworks' header directory, together with the links to the include directory of each one of their sub-frameworks. The script can be found here: https://github.com/emcrisostomo/link-osx-framework-headers

Hope this helps.

Enrico M. Crisostomo
  • 1,653
  • 1
  • 17
  • 26
0

goto Your Project>Properties>MacOS X C++ Linker>Command Where "g++" add " -framework OpenCL"

nullqube
  • 2,959
  • 19
  • 18
0

OK so I had to include like this:

#include <cl.h>

Then add an include to the folder with the header file in Properties > C/C++ General > Paths and Symbols resulting in the following option for the compiler:

-I/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers

And, most notably, had to add the following options for libraries path and framework inclusion under Properties > C/C++ Build > Settings:

-L/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries -framework OpenCL

The above did the trick.

JohnIdol
  • 48,899
  • 61
  • 158
  • 242