[fpc-devel]Linking with C

Sergey Korshunoff Sergey.Korshunoff at p5.f434.n5020.z2.fidonet.org
Fri Sep 7 04:25:11 CEST 2001


Hello!

A problems with current version of FPC:

1) Linking a C library to pascal program is done by code (t_linux.pas):
   s:=librarysearchpath.FindFile('crtbegin.o',found)+'crtbegin.o';
   if found then
     LinkRes.AddFileName(s);
   s:=librarysearchpath.FindFile('crti.o',found)+'crti.o';
   if found then
     LinkRes.AddFileName(s);

This is wrong: crti.o must go _before_ crtbegin.o
(in t_beos.pas we have a right sequence, but why this is wrong for other
targets?)

==================================================================
-+- t_linux.pas.bak     Wed Jun 13 08:36:28 2001
+++ t_linux.pas Fri Aug 31 20:17:10 2001
@@ -324,10 +324,10 @@
   { try to add crti and crtbegin if linking to C }
   if linklibc then
    begin
-     s:=librarysearchpath.FindFile('crtbegin.o',found)+'crtbegin.o';
+     s:=librarysearchpath.FindFile('crti.o',found)+'crti.o';
      if found then
       LinkRes.AddFileName(s);
-     s:=librarysearchpath.FindFile('crti.o',found)+'crti.o';
+     s:=librarysearchpath.FindFile('crtbegin.o',found)+'crtbegin.o';
      if found then
       LinkRes.AddFileName(s);
    end;
==================================================================

2) There is a code in t_linux.pas:
     { be sure that libc is the last lib }
     if linklibc then
      LinkRes.Add('-lc');
     { when we have -static for the linker the we also need libgcc }
     if (cs_link_staticflag in aktglobalswitches) then
      LinkRes.Add('-lgcc');     { be sure that libc is the last lib }

But I can not get -lgcc in link.res ( FPC -s -XS) ???
After looking in sources:
   cs_link_staticflag is not set by -XS or by -XX, but is set by
   _nondocumented_ flag -Xt

What is purpose of -Xt swith? Why we can not use -XS and -XX
insteed of -Xt ? If -Xt is a right thing, then why it is
not in FPC help output (FPC -h)?

Regards,
    Sergey Korshunoff

-+- GoldED+/LNX 1.1.4.7

To: fpc-devel at deadlock.et.tudelft.nl






More information about the fpc-devel mailing list