Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking against Apple frameworks with gcc

I've created some wrapper functions that encapsulate working with CoreAudio, and the goal is to create a C library that I can use with some command line C++ tools. So far things are working well. I took a sample project, modified it, and it builds and runs in XCode. I'd like to skip XCode altogether and build the library with gcc and a Makefile.

How can I link against an Apple Framework? Are Frameworks just shared libraries that I could include in the -l and -L options on gcc?

like image 619
Dr. Watson Avatar asked Nov 22 '09 21:11

Dr. Watson


People also ask

How do you make a link a weak framework?

Weak Linking to Entire Frameworks In order to create a weak link to a symbol, the framework containing the symbol must explicitly add the weak_import attribute to it (see Marking Symbols for Weak Linking).


1 Answers

Here's an example:

gcc -framework CoreServices -o test test.c

From the man page of Apple's gcc (i686-apple-darwin10-gcc-4.2.1):

   In addition to the options listed below, Apple's GCC also accepts and    passes nearly all of the options defined by the linker ld and by the    library tool libtool.  Common options include -framework, -dynamic,    -bundle, -flat_namespace, and so forth.  See the ld and libtool man    pages for further details. 

And from ld's man page:

 -framework name[,suffix]              This option tells the linker to search for `name.frame-              work/name' the framework search path.  If the optional suffix              is specified the framework is first searched for the name              with the suffix and then without (e.g. look for `name.frame-              work/name_suffix' first, if not there try `name.frame-              work/name'). 
like image 147
Jeremy L Avatar answered Sep 21 '22 14:09

Jeremy L