Pascal Viandier wrote:
Hi gpc crew,
Is there a way to generate a shared object (.so) under unix with gpc? I found nothing about this in GPC documentation. I tried "gpc --automake -o foo.so foo.pas" on the command line (foo.pas being a module) This does not work: I get an error about an undefined reference to 'main'
Is it possible at all to generate a shared object with gpc? Does someone have any clue?
Assuming that mylib.pas is a unit, then you would do something like
On Mac OS X (for a dylib)
gpc --automake -dynamiclib -Wl,-dylib_install_name,@executable_path/../lib/mylib.dylib -Wl,-init,mylib_init -o mylib.dylib mylib.pas
On Mac OS X (for a bundle)
gpc --automake -bundle -o mylib.bundle mylib.pas
On Linux (I guess)
gpc --automake -shared -Wl,-soname=/usr/local/lib/mylib.so -o mylib.so mylib.pas
The -Wl,-init,mylib_init for a Mac OS X dylib instructs the system to call mylib_init on library loading. Then, mylib_init can automatically call GPC_Initialize (see http://www.gnu-pascal.de/crystal/gpc/en/mail12692.html). I don't know the Linux equivalent.
The above is a rough outline from memory.
Regards,
Adriaan van Os