When building your projects in Mac OS X, simply supplying or modifying the compiler flags of a few key options is all you need to do to port most programs. These are usually specified by either the CFLAGS or LDFLAGS variable in your makefile, depending on which part of the compiler chain interprets the flags. Unless otherwise specified, you should add these flags to CFLAGS if needed.
Note: The 64-bit toolchain in Mac OS X v10.4 and later has additional compiler flags (and a few deprecated flags). These are described in more detail in 64-Bit Transition Guide.
Some common flags include:
-flat_namespace (in LDFLAGS)Changes from a two-level to a single-level (flat) namespace. By default, Mac OS X builds libraries and applications with a two-level namespace where references to dynamic libraries are resolved to a definition in a specific dynamic library when the image is built. Use of this flag is generally discouraged, but in some cases, is unavoidable. For more information, see “Understanding Two-Level Namespaces.”
-bundle (in LDFLAGS)Produces a Mach-O bundle format file, which is used for creating loadable plug-ins. See the ld man page for more discussion of this flag.
-bundle_loader executable (in LDFLAGS)Specifies which executable will load a plug-in. Undefined symbols in that bundle are checked against the specified executable as if it were another dynamic library, thus ensuring that the bundle will actually be loadable without missing symbols.
-framework framework (in LDFLAGS)Links the executable being built against the listed framework. For example, you might add -framework vecLib to include support for vector math.
-mmacosx-version-min versionSpecifies the version of Mac OS X you are targeting. You must target your compile for the oldest version of Mac OS X on which you want to run the executable. In addition, you should install and use the cross-development SDK for that version of Mac OS X. For more information, see Cross-Development Programming Guide.
More extensive discussion for the compiler in general can be found at http://developer.apple.com/releasenotes/DeveloperTools/.
Last updated: 2008-04-08