global variable in shared library
How to create a shared library that contains global variables in it, using XCode?
This was possible in Code Warrior by exporting symbols in an .exp file. For completeness’ sake, David Z’s instructions on how that was done (from about 5 years ago) are included below.
Perhaps there is a newer, hipper way to accomplish the same thing.
Thanks for your help,
In 2001, David Z said:
The 30-second recipe. Let’s say you want to make a shared library that has a global variable in it. Make a .c source file with:
Add this file to a project that you based on one of your Max/MSP
external object projects. Remove all other files but this file in this project.
Let’s say your project file is called globoproj.mcp. Create a text file called globoproj.mcp.exp and place in the same folder as globoproj.mcp.
on a line by itself in the globoproj.mcp.exp file. (Add any other
exported symbols on subsequent lines.)
In the Metrowerks Code Warrior PPC PEF settings file, choose "Use .exp file" for Export Symbols:.
Rename the PPC target, oh, I don’t know, GloboLib. Build it.
Make sure that in the PPC Project settings panel, the Project
Type is set to Shared library.
In your external object(s), add GloboLib to your project. You
should now be able to say, "extern long globo" in any external
object source file whose project include GloboLib.
Functions work similarly. Place function in a file included in
globo.mcp, add it to the globo.mcp.exp file as an exported
When your external object is loaded, it will look for the shared
library, and if it can’t find it, you will see a "can’t fragload error" in the Max window. The shared library can be placed in the
same folder as the Max application or in the Extensions folder
(or any subdirectory of the Extensions folder).
On OS X, you will place it in any Library folder inside a
folder called CFMSupport.
This is an adequate solution if you are the only person who
will ever use your shared library. You can also make a "stub
file" that just lists the exports using the MPW tool MakeStub.
But only people who want to distribute shared libraries as
part of SDKs (like me) really need to worry about this. Old-time
extern developers may remember that you used to include the
Max application itself in the extern project. This still works, but these days the preferred method is to include MaxLib, which is a stub file.
On Jul 22, 2006, at 3:14 PM, Kurt Ralske wrote:
> How to create a shared library that contains global variables in
> it, using XCode?
Unless you wan to restrict some globals and not others, XCode by
default exports all functions and global variables in your code which
are not declared static.
> This was possible in Code Warrior by exporting symbols in an .exp
> file. For completeness’ sake, David Z’s instructions on how that
> was done (from about 5 years ago) are included below.
XCode also supports .exp style files which may specify which
functions and data to export (or alternately which ones *not* to
Since this is a general XCode programming issue, rather than
something specific to MaxMSP, I’d recommend checking out the Apple
developer site. For example:
Also note that or standard C code, you typically need to add an
underscore to the exports file symbol name, which wasn’t the case for