2

I have Cg installed to /Library/Frameworks/Cg.framework. It looks like this on disk:

enter image description here

My XCode 3.2.6 project has Library/Frameworks as a Framework Search Path and -Framework Cg in "Other Linker Settings" but when I try to #include <Cg/cg.h> it can't find the file. If I directly add /Library/Frameworks/Cg.framework/Headers to my "Header Search Paths" I can `#include ' but it fails to link with error "Framework not found Cg".

I don't really understand what a Mac Framework is - is it anything special or just a regular directory? It seems as if Xcode simply doesn't understand /Library/Frameworks/Cg.framework is a framework for some reason.

I'm not sure if this is related: https://stackoverflow.com/questions/5293940/xcode-3-2-6-stops-looking-in-library-frameworks

Any help understanding what's wrong would be appreciated.

I tested a simple test from the command line:

test.cpp

#include <Cg/cg.h>

void f()
{
  CGcontext context = cgCreateContext();
}

Just running "gcc -c test.cpp" succeeds (-c says don't link). I also ran "gcc -M test.cpp" (list dependencies): /Library/Frameworks/Cg.framework/Headers/cg.h So the framework seems fine... how can running gcc without passing any search paths work, but XCode can't see the framework when it calls gcc?

Community
  • 1
  • 1
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

3 Answers3

2

I think you did not added the Cg framework to the project properly. Click on your target -> click Build Phases (a tab)->in "Link Binary with Libraries" click + sign -> fin Cg framework and add it. Now the following should compile just fine:

 #include <Cg/cg.h>
 void a() {

    CGcontext context = cgCreateContext();
 }

I also presume that you installed the framework using the provided image (Cg-something.dmg)

You dont have to alter any search path manually. When the framework is added as shown above, the compiler will look there.

Ondrej Peterka
  • 3,349
  • 4
  • 35
  • 49
  • I don't have 'Build Phases' in 3.2.6 but when I do 'Get Info' and try to add Cg.framework to Linked libraries, it doesn't appear in the list. – Mr. Boy May 09 '12 at 21:39
  • You are right, I missed the fact you have older XCode. Nevertheless, there was the same concept of Frameworks in the 3.2.6. Use the answer from this question to add the framework in 3.2.6: http://stackoverflow.com/questions/1566350/how-to-add-quartz-core-framework-in-new-xcode-3-2 . If it will still not be found, you did not install the Cg framework properly. Try to install it once more form the *.dmg file. – Ondrej Peterka May 10 '12 at 04:58
  • I am sure the framework is installed OK, I re-installed to check and added a screenshot to my question. I do have `Library/Frameworks` in my "Framework Search Path". As far as I can see, XCode/Mac simply doesn't _recognize_ /Library/Frameworks/Cg.framework as a framework. – Mr. Boy May 10 '12 at 10:13
  • 1
    Well I have just tried to download the CG dmg install it in vmware with XCode 3.2.6. I was able to compile the code I wrote above. I really jsut created C++ project added the framework and it worked. So it is really weird. From what I see in your screenshot I can tell I have the same content of Cg.framework directory. It is especially weird that other frameworks just work for you. – Ondrej Peterka May 10 '12 at 12:10
  • Maybe you could check one more thing, if you are really stuck. Look at the Current alias ... it should have as its original the path to Framework 1.0 (/Library/Frameworks/Cg.framework/Versions/1.0) – Ondrej Peterka May 10 '12 at 12:13
  • Yes that all seems fine, the Framework all appears to exist properly. Can you suggest a way to check if it _is_ seen as a framework, and/or test without using XCode? e.g if I create a test.cpp file based on your code snippet, how would I compile from command-line? – Mr. Boy May 10 '12 at 14:29
  • You can try: `gcc -framework Cg File.cpp` in cmd line. Anyway, if I were you, I would try to set up new C++ project in XCode 3.2.6 with only one file with the code I provided. Than add there the Cg framework. If it will work (it should) I would compare the build settings of the targets and the build logs (of your original and sample project) For how to get build logs see for example: http://stackoverflow.com/questions/1488931/how-do-you-show-xcodes-build-log-trying-to-verify-if-iphone-distribution-buil. – Ondrej Peterka May 13 '12 at 00:58
  • I tried this, I get exactly the same result in Xcode... I add the framework to a default C++ console app (hello world) and add the single line `#include ` and it doesn't work. I'm getting slowly more convinced either the framework or XCode has a bug, is there any way I can check? – Mr. Boy May 14 '12 at 21:58
1

I'm not sure if this is relevant, but I was having similar problems with the CG library. It would link with 10.5 but not 10.6. I eventually realized that my 10.6 sdk directory was messed up: instead of /Developer/SDKs/MacOSX10.6.sdk/Library having a sym link to the Frameworks directory in it, it had a Frameworks directory with a sym link inside the Frameworks directory.

It should have worked anyway (I had supplied the absolute path for the cg framework AND added the /library/frameworks directory to the search path) but it didn't. Actually, why anything linked properly with the 10.6 sdk directory messed up in the first place, I don't know...

cmg
  • 11
  • 1
0

Well I have an answer as to why, but not how. Cahnging the SDK from 10.6 to 10.5 meant things magically worked. BUT both SDK dirs on disk have identical links to the correct Frameworks dir, and this is a clean 10.6 install not an upgraded 10.5 machine, so no idea why. Anyone who can write an answer explaining this and ideally offering a solution is welcome to the bounty!

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589