You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to specify framework in clang?

I'm working through a tutorial (in Kochan's Objective C, 4th) that gives the following command line:


$ clang -fobjc-arc –framework Foundation main.m -o prog1


Apparently this worked in some earlier version of clang (or Xcode), but all I get is an error:


clang: error: no such file or directory: '–framework'
clang: error: no such file or directory: 'Foundation


My environment is:


Lion 10.7.3

clang ver 3.1

Xcode ver 4.3


The clang man page doesn't mention a 'framework' argument. Any suggestions on a change, or hints on where to look for a solution?


Danke!

Mac OS X (10.7.3)

Posted on Feb 22, 2012 12:31 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 22, 2012 4:52 PM

Did you include the path to the framework using the -F switch?


eg., -F/System/Library/Frameworks


After that I believe you can refer to the specific framework using the -l switch as for libraries (although I haven't been on the command line in a few months)


eg., -lFoundation


And the man page for clang is remarkably sparse, considering that it takes almost the entire body of gcc arguments.

6 replies
Question marked as Top-ranking reply

Feb 22, 2012 4:52 PM in response to glimpse

Did you include the path to the framework using the -F switch?


eg., -F/System/Library/Frameworks


After that I believe you can refer to the specific framework using the -l switch as for libraries (although I haven't been on the command line in a few months)


eg., -lFoundation


And the man page for clang is remarkably sparse, considering that it takes almost the entire body of gcc arguments.

Feb 22, 2012 6:15 PM in response to g_wolfman

g_


Thanks again! I never got the -F switch to do anything except produce more squawking from clang. It was (maybe is) a great idea to be able to spec it on the command line, but it didn't work for me.


However, it got me thinking: It's the PATH, dummy! So I tried adding the path to Frameworks, and that worked. For posterity, I've included a few lines below to show what finally worked.


assuming bash:


- check your PATH variable first:


$ echo $PATH


-assuming /System/Library/Frameworks is not included in PATH, add it:


$ PATH=$PATH:/System/Library/Frameworks


-now we're ready for Mr. Kochun's incantation:


$ clang -fobjc-arc -framework Foundtion main.m prog1


Please let me know if you find the command-line switch that works.

Feb 24, 2012 12:05 PM in response to glimpse

Hi,


I've been having the exact same problem and have tried your method to fix it but I am still getting the same error message.


Iv added the line:


PATH=$PATH:/System/Library/Frameworks


to my .bash_profile and it shows when I echo my $PATH but i still get the same error message when i try to compile.


Any other ideas?


I am using the exact same setup as you have described,


Thanks,

Aug 31, 2012 12:58 PM in response to glimpse

I to am working through Stephen Kochan's "Programming in Objective-C 4th Ed" and got rather stuck when it came to Program 16.6 - Working with files.


Personally I think this program needs a bit more explanation explaining that it is run in the terminal window rather than in Xcode, especially for the Unix novice. The other annoying aspects are that the explanation of how to compile the code is on page 18 but doesn't actually tell you this, and then the command is actually wrong!!


However, after much trial and error I finally got it working, so hopefully this is of help to others.


I found the following command line produces the required output file that runs:


clang -fobjc-gc /System/Library/Frameworks/Foundation.framework/Foundation copy.m -o copy

(Run this in the directory created by Xcode for the project where the copy.m file is located)


Basically I ignored the "-framework" and "-F" options and just put the full path to the framework. And as you can also see the "-fobjc-arc" is replaced with '-fobjc-gc". In fact the '-fobjc-arc" option is not listed in the MAN pages for CLANG!.


$ ./copy testfile testfile.copy

2012-08-31 20:35:18.096 copy[7136:707] Copy of testfile to testfile.copy succeeded!

$


So as you can see seems to work ok for me, not quite as documented in the book - but got there in the end.


Hope this helps.

How to specify framework in clang?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.