Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-08

FPC + GCC

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hello,

I'm a begginer in linux programming and I got some problems while trying to mix pascal and gcc code...

On the pascal side i wrote the following file:

----------- teste.pas---------------
{$LINK testec.o}
program teste_linker;
uses Crt, Linux;
procedure teste_em_c; cdecl; external;
Begin
        teste_em_c;
end.
------eof(teste.pas)------------------

And my gcc source is as follows:

------------testec.c----------------

#include <stdio.h>

void teste_em_c()
{
        printf("Ola Mundo\n");
}

------eof(testec.c)-------------------

I've read how to do that on
http://www.freepascal.org/docs-html/prog/node6.html but the command line presented in this manual  (using the -Sv switch) shows me an error message, something like "obsolete option" . So i tryed:

tX gcc -c testec.c -o testeo.c
tX fpc teste.pas

Free Pascal Compiler version 1.0.4 [2001/01/22] for i386 Copyright (c) 1993-2000 by Florian Klaempfl
Target OS: Linux for i386
Compiling teste.pas
Assembling teste_linker
Linking teste
testec.o: In function `teste_em_c':
testec.o(.text+0x9): undefined reference to `printf' teste.pas(10,4) Warning: Error while linking
Closing script ppas.sh
9 Lines compiled, 0.0 sec

After that I tryed the -Xc switch (link with standard C lib),  wich gave me the same error...

Does anybody knows how to do this?

I've also tryed to compile only (-s option) and link the link.res file with GCC:

-----------LINK.RES--------------------------------- SEARCH_DIR(/lib/)
SEARCH_DIR(/usr/lib/)
SEARCH_DIR(/usr/X11R6/lib/)
SEARCH_DIR(/usr/lib/gcc-lib/i386-slackware-linux/egcs-2.91.66/) SEARCH_DIR(/usr/local/lib/fpc/1.0.4/units/linux/rtl/) SEARCH_DIR(/usr/local/lib/fpc/1.0.4/units/linux/paszlib/) SEARCH_DIR(/usr/local/lib/fpc/1.0.4/units/linux/api/) SEARCH_DIR(/usr/local/lib/fpc/1.0.4/units/linux/fcl/) SEARCH_DIR(/usr/local/lib/fpc/1.0.4/units/linux/)
SEARCH_DIR(/usr/local/lib/fpc/1.0.4/)
INPUT(
/usr/local/lib/fpc/1.0.4/units/linux/rtl/prt0.o
/usr/local/lib/fpc/1.0.4/units/linux/rtl/strings.o /usr/local/lib/fpc/1.0.4/units/linux/rtl/linux.o
/usr/local/lib/fpc/1.0.4/units/linux/rtl/crt.o
/usr/local/lib/fpc/1.0.4/units/linux/rtl/syslinux.o teste.o
testec.o
)
------------------------------------------------

But:

tX gcc link.res
/usr/local/lib/fpc/1.0.4/units/linux/rtl/prt0.o: In function `_start': /usr/local/lib/fpc/1.0.4/units/linux/rtl/prt0.o(.text+0x0): multiple definition of `_start'
/usr/lib/crt1.o(.text+0x0): first defined here
collect2: ld returned 1 exit status

Please, could anyone tell me what is wrong?
I'm trying to port TP7 code and there are some things that I would like to rewrite in C, for future expansions.... Can you help me ?

Best regards,
Mauricio

Marco van de Voort
to Unknown author
Show quoted text 7 lines
I'm a begginer in linux programming and I got some problems while trying to mix pascal and gcc code... On the pascal side i wrote the following file: ----------- teste.pas--------------- {$LINK testec.o}
add
{$LINKLIB c}

reason: printf is in the libc library which is linked by the linklib command.