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?
Regards
Pascal Viandier
On Oct 12, 2007, at 1:22 PM, 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?
It depends upon the options supported by the build target. If the target system supports shared objects/libraries, you'll need additional target specific, command line parameters.
To find out if your system supports shared objects/libraries and what the command line parameters to use are, try gpc --target-help or consult the system's gcc documentation. If neither of those help, the authoritative documentation can be found in gcc/config sources used for the target OS building. (You may have to a little looking around in the config files used. There seems to be a variety of ways different target OS's get their command line specs defined. Some variant of the root words "share" or "dynamic" seems to be the common command line parameter naming scheme used.)
If you need more specific help, try posting your gpc -v information so people know what the the specific target it is you need the command line parameter(s) for.
Gale Paeper gpaeper@empirenet.com
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
<snip>
On Linux (I guess)
gpc --automake -shared -Wl,-soname=/usr/local/lib/mylib.so -o
mylib.so mylib.pas
<snip>
Thanks a lot for the hints; this works on my Linux box I use for development. But my target platform is SPARC Solaris 10. When I put -shared on the gpc command-line, the linker complains about all symbols of libgpc.a.
<gnu-pascal> gpc -v --automake -shared -o module1.so module1.pas Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/specs Configured with: ../gcc-3.4.4/configure --enable-languages=pascal Thread model: posix gpc version 20051116, based on gcc-3.4.4 /usr/local/libexec/gcc/sparc-sun-solaris2.10/3.4.4/gpc1 -quiet -v module1.pas -quiet -dumpbase module1.pas -mcpu=v7 -auxbase module1 -famtmpfile=/var/tmp//ccTaVS8M.gpa -fautomake -version -o /var/tmp//cc2gQmmp.s GNU Pascal version 20051116, based on gcc-3.4.4 (sparc-sun-solaris2.10) compiled by GNU C version 3.4.6. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU Pascal Compiler PreProcessor version 20051116, based on gcc-3.4.4
/usr/ccs/bin/as -V -Qy -s -xarch=v8 -o /var/tmp//ccN8lK2a.o /var/tmp//cc2gQmmp.s /usr/ccs/bin/as: Sun Compiler Common 10 Patch 05/06/2005 /usr/local/libexec/gcc/sparc-sun-solaris2.10/3.4.4/collect2 -V -G -dy -z text -Y P,/usr/ccs/lib:/usr/lib -Qy -o module1.so /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/crti.o /usr/ccs/lib/values-Xa.o /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/crtbegin.o -L/usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/../../.. /var/tmp//ccN8lK2a.o -lgpc -lm -lgcc_s -lgcc_s /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/crtend.o /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/crtn.o ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.486 Text relocation remains referenced against symbol offset in file <unknown> 0x3600 /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/libgpc.a(error.o) <unknown> 0x3604 /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.4/libgpc.a(error.o) <zillions of errors...> ld: fatal: relocations remain against allocatable but non-writable sections collect2: ld returned 1 exit status
The flags passed to the linker look good as far as I can see in the documentation of Sun ld. Should I recompile libgpc.a with the -fPIC compiler option to make the code position-independent?
Regards
Pascal Viandier
Pascal Viandier wrote:
The flags passed to the linker look good as far as I can see in the documentation of Sun ld. Should I recompile libgpc.a with the -fPIC compiler option to make the code position-independent?
Yes, something like
cd gcc/p/rts make clean make CFLAGS="-O2 -fPIC"
or make libgpc shared also.
cd gcc/p/rts make clean make GPCSOLIBNAME=libgpc_xxx.so WITH_SHARED=yes
Regards,
Adriaan van Os
I rebuild libgpc.a and build libgpc.2.1.so and it works like perfect.
If this is of interest for someone, the exact command to build a shared object from a Pascal source with Sun Solaris is:
gpc --automake --shared -fPIC module.pas -o module.so
If -fPIC is not specified, the assembler does not generate position independent code (the "-KPIC" parameter is not passed to "as")
Thank you very much for your help.
Kind regards
Pascal Viandier
Yes, something like
cd gcc/p/rts make clean make CFLAGS="-O2 -fPIC"
or make libgpc shared also.
cd gcc/p/rts make clean make GPCSOLIBNAME=libgpc_xxx.so WITH_SHARED=yes
Regards,
Adriaan van Os