[plt-scheme] linking with mzc

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Mon Nov 21 22:27:35 EST 2005

Matthew Flatt wrote:

>At Sat, 19 Nov 2005 18:46:40 -0500, Jon Rafkind wrote:
>>Everything compiled ok but when I load the library mzc outputted, 
>>_loader.dylib, using the standard ffi-lib technique I get the following:
>>~/tmp/xquest-0.1 $ mzscheme -f xquest.ss
>>Welcome to MzScheme version 299.406, Copyright (c) 2004-2005 PLT Scheme Inc.
>>ffi-lib: couldn't open "liballeg.dylib" (dlcompat: dyld: mzscheme 
>>Undefined symbols:
>Sorry - I don't quite follow what you're doing. "_loader.dylib" is
>normally the output of compiling multiple Scheme sources (and linking
>them into a single shared library). But you're starting with
>Objective-C code, right? Can you tell me more about the sequence of mzc
>commands that you use, and more about the content of the input files?
Sure, I have a bunch of .c and .m files. The .m files are the OS X 
drivers for the Allegro library. I compile the C files like so:

mzc ++ccf -DALLEGRO_SRC --cc ++ccf -DALLEGRO_LIB_BUILD ++ccf -Wall ++ccf 
-Wno-unused ++ccf -Wno-long-double  ++ccf -O2 ++ccf -funroll-loops ++ccf 
-ffast-math ++ccf -fomit-frame-pointer ++ccf -fno-common ++ccf -pipe 
++ccf -dynamic ++ccf -DALLEGRO_USE_C ++ccf -I. ++ccf -I./include  

Which spits out foobar.o. Then I compile all the .m files with the same 
thing except replace foobar.c with barbaz.m and I get an output of 
barbaz.o. I then try to link all the .o files together to make a 
standard C dynamic library with the following:

mzc -l ++ldf -prebind ++ldf -seg1addr ++ldf 0x30000000 --ldf-show ++ldf 
-framework ++ldf Cocoa ++ldf -framework ++ldf Carbon ++ldf -framework 
++ldf IOKit ++ldf -framework --ldf-show ++ldf System ++ldf -framework 
++ldf CoreAudio ++ldf -framework ++ldf AudioUnit ++ldf -framework ++ldf 
AudioToolbox ++ldf -framework ++ldf QuickTime --ldf-show *.o

which produces _loader.dylib. All of the options to mzc come straight 
from the Allegro library.

The symbols that I showed above, __allegroscheme_module_name and the 
rest, come from one of the .c files, not .m.

Posted on the users mailing list.