LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   free pascal: linking error (https://www.linuxquestions.org/questions/programming-9/free-pascal-linking-error-556296/)

kristof_v 05-24-2007 03:15 AM

free pascal: linking error
 
Hi,
I'm trying to compile some code with this command:
fpc -Sd -pg OrchidFW.lpr

everything goed OK until the linking step:
Linking OrchidFW
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.1.1/crtbegin.o when searching for /usr/lib/gcc/x86_64-redhat-linux/4.1.1/crtbegin.o
/usr/bin/ld: cannot find /usr/lib/gcc/x86_64-redhat-linux/4.1.1/crtbegin.o
OrchidFW.lpr(74,1) Error: Error while linking

the file /usr/lib/gcc/x86_64-redhat-linux/4.1.1/crtbegin.o does exist however.

any ideas??

osor 05-24-2007 03:10 PM

Perhaps you compiled x86 object code and you’re linking with x86-64 object code?

kristof_v 05-24-2007 03:12 PM

how can i compile it for 32 bit then, any idea??

osor 05-24-2007 04:34 PM

Quote:

Originally Posted by kristof_v
how can i compile it for 32 bit then, any idea??

My guess was that you already compiled for 32-bit, you were just trying to link to 64-bit (the output of “file the_object_file.o” should tell you for sure). So your two options are
  1. Try to compile in 64-bit mode.
  2. Try to link your 32-bit object to 32-bit system libraries.
You haven’t really told us the commands used to link, so I will just point out that in multilib setups, the 32-bit gcc libraries might be located somewhere like “/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/crtbegin.o”. You can also use issue the linker command using options to specify i386 code (e.g., “ld -m elf_i386”), in which case the 32-bit libraries will automagically be selected (I think).

kristof_v 05-25-2007 03:34 AM

you are right!
there is a directory gcc... /32/crtbegin.o so I should use that one.
do you know how I can provide this specific 32 lib to the linker?

all the source code seems to be compiled (every .pas file has a .o counterpart)
so the only thing we need to do now is the linking to the 32 lib right?

any idea on how to do that?
the executable is called OrchidFW.o and the path to the 32 lib is /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/crtbegin.o

kristof_v 05-25-2007 09:07 AM

a small update:

I got around the linking error by editing the /etc/fpc.cfg file from:
Code:

# searchpath for libraries
-Fl/usr/lib/gcc/x86_64-redhat-linux/4.1.1

to:
Code:

# searchpath for libraries
-Fl/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32

but now we have another (linking) error

# fpc -Sd -pg OrchidFW.lpr
Free Pascal Compiler version 2.0.4 [2006/08/20] for i386
Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for i386
Compiling OrchidFW.lpr
Linking OrchidFW
/usr/bin/ld: skipping incompatible /usr/lib64/libdag.so when searching for /usr/lib64/libdag.so
/usr/bin/ld: cannot find /usr/lib64/libdag.so
OrchidFW.lpr(74,1) Error: Error while linking
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)


/usr/lib64/libdag.so exists but that's the 64 bit version and we need the 32 bit version offcourse.
/usr/lib/libdag.so, however, does not exist.

but there is a file /usr/local/lib/libdag.so so that is a 32 bit version.
there is also a /usr/local/lib64/libdag.so

but I don't see where I need to put that in the fpc.cfg file.
this is in fpc.cfg now:

Code:

# searchpath for libraries
-Fl/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32
-Fl/usr/local/lib

now I found a source file (EndaceNICDecoderUnit.pas) that has the following line:
Code:

{$link /usr/lib64/libdag.so}
so I changed this to:
Code:

{$link /usr/local/lib/libdag.so}
and then I call fpc again:
Code:

# fpc -Sd -pg OrchidFW.lpr
Free Pascal Compiler version 2.0.4 [2006/08/20] for i386
Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for i386
Compiling OrchidFW.lpr
Compiling EndaceNICDecoderUnit.pas
EndaceNICDecoderUnit.pas(146,3) Note: Local variable "PacketData" not used
EndaceNICDecoderUnit.pas(148,3) Note: Local variable "data" not used
EndaceNICDecoderUnit.pas(149,3) Note: Local variable "i" not used
EndaceNICDecoderUnit.pas(177,14) Warning: range check error while evaluating constants
EndaceNICDecoderUnit.pas(177,46) Warning: range check error while evaluating constants
Linking OrchidFW
/usr/bin/ld: skipping incompatible /usr/local/lib/libdag.so when searching for /usr/local/lib/libdag.so
/usr/bin/ld: cannot find /usr/local/lib/libdag.so
OrchidFW.lpr(74,1) Error: Error while linking
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)


osor 05-25-2007 02:28 PM

Quote:

Originally Posted by kristof_v
but there is a file /usr/local/lib/libdag.so so that is a 32 bit version.

How did you verify that this is a 32-bit version? In general, you might use the file command. E.g.,
Code:

$ file /lib{32,64}/libz.so.1.2.3
/lib32/libz.so.1.2.3: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), stripped
/lib64/libz.so.1.2.3: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), stripped

Also, I think finding out how to get fpc to emit 64-bit object code might be easier than finding 32-bit versions of the libraries against which your program links. Perhaps you need the x86-64 version of fpc? On my computer, this is output of invoking fpc to give information:
Code:

$ fpc -i
Free Pascal Compiler version 2.0.4

Compiler Date      : 2006/08/24
Compiler CPU Target: x86_64

Supported targets:
  Linux for x86-64
  FreeBSD for x86-64

Supported CPU instruction sets:
  ATHLON64

Supported FPU instruction sets:
  SSE64

This program comes under the GNU General Public Licence
For more information read COPYING.FPC

Report bugs,suggestions etc to:
                bugs@freepascal.org

Perhaps you should download and install the 64-bit version of fpc (it will simplify your life).

kristof_v 05-29-2007 03:33 AM

hi osor,

I installed the 64 bit version of fpc as you suggested, and indeed, we made some progress.
We don't get the incompatible libdag.so errors anymore, but we still get 1 error while linking though:

Code:

Free Pascal Compiler version 2.1.4 [2007/05/07] for x86_64
Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for x86-64
Compiling OrchidFW.lpr
OrchidFW.lpr(74,1) Warning: Object /usr/lib64/libdag.o not found, Linking may fail !
Linking OrchidFW
/usr/bin/ld: cannot find /usr/lib64/libdag.o
OrchidFW.lpr(74,1) Error: Error while linking
OrchidFW.lpr(74,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)

I searched all the soruce code files and OrchidFW.lpr for a reference to libdag.o, but libdag.o isn't in any of the sourcecode files.

But there is one source code file (EndaceNICDecoderUnit.pas) which has a reference to libdag.so:

Code:

{$link /usr/lib64/libdag.so}
any idea??

*edit:
I also searched for libdag.o on the system but it doesn't exist, but libdag.so does exist

kristof_v 05-29-2007 04:47 AM

problem solved!!

I found a file called libdag.a in the dag dir.
the content looked binary so I figured it was a compiled object file that just ended with .a instead of .o
I copied libdag.a to libdag.o, put in the right directory (/usr/lib64) and the program compiled/linked without problems Smile


All times are GMT -5. The time now is 12:58 AM.