[fpc-devel] Problems linking FPC-built library into C program on linux x86_64
Dominique Leducq
dleducq at magellan-ing.fr
Thu May 25 01:26:27 CEST 2006
On Wed, 24 May 2006 15:40:27 +0200
Dominique Leducq <dleducq at magellan-ing.fr> wrote:
> On Wed, 24 May 2006 11:49:03 +0200 (CEST)
> Michael Van Canneyt <michael at freepascal.org> wrote:
>
> >
> >
> > On Wed, 24 May 2006, Dominique Leducq wrote:
> >
> > > Hi again,
> > >
> > > I still don't succeed in linking Free Pascal compiled code with a C program.
> > >
> > > When linking with the shared library built by fpc, I have problems with undefined symbols, which are defined in the loaders.
> > >
> > > $ gcc -o test_shared test2.o -L. -lsoTest3
> > > ./libsoTest3.so: undefined reference to `__stkptr'
> > > ./libsoTest3.so: undefined reference to `_haltproc'
> > > ./libsoTest3.so: undefined reference to `operatingsystem_parameter_argc'
> > > ./libsoTest3.so: undefined reference to `operatingsystem_parameter_argv'
> > > collect2: ld returned 1 exit status
> > >
> > > When linking in the loader prt0.o too, there are symbol conflicts with /usr/lib/crt1.o (_start, __data_start) if I call ld through gcc.
> > >
> > > $ gcc -o test_shared test2.o prt0.o -L. -lsoTest3
> > > prt0.o: In function `_start':
> > > (.text+0x0): multiple definition of `_start'
> > > /usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/crt1.o:../sysdeps/x86_64/elf/start.S:65: first defined here
> > > prt0.o: In function `data_start':
> > > (.data+0x0): multiple definition of `__data_start'
> > > /usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/crt1.o:(.data+0x0): first defined here
> > > collect2: ld returned 1 exit status
> > >
> > >
> > > Exactly the same happens when linking statically.
> > >
> > >
> > > If I call ld directly, linking succeeds, but the main() of the C program never gets called...
> > >
> > > However, according to the FPC Programmer's Guide, "using a pascal library from a C program" (12.4) seems to be supported...
> > >
> > > Do I miss something ?
> >
> > That statement means that you can create a separate library,
> > which can be called from a C program.
> >
>
> That is actually what I want to do. How can I achieve this ? I followed the steps in the Programmer Guide, to no avail.
>
OK, I've done it with this little trick :
$ gcc -c test3.c
$ gcc -o test3 test3.o dummy.o -L. -lsoTest5
with the source of dummy.c:
#define NULL (void *)0
long operatingsystem_parameter_argc = 0;
char **operatingsystem_parameter_argv = NULL;
char **operatingsystem_parameter_envp = NULL;
void *__stkptr = NULL;
void _haltproc(long e)
{
return;
}
When calling a library function that do no IO (only arithmetics on the parameters), it works.
When doing simple IO (writeLn), it doesn't: I see calls to handleerror_frame, get_frame, get_caller_frame, get_caller_addr, break_error... when debugging, following calls to write_text_pchar_as_array and IOcheck
Dominique Leducq.
More information about the fpc-devel
mailing list