LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2007, 03:15 AM   #1
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Rep: Reputation: 15
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??
 
Old 05-24-2007, 03:10 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Perhaps you compiled x86 object code and you’re linking with x86-64 object code?
 
Old 05-24-2007, 03:12 PM   #3
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Original Poster
Rep: Reputation: 15
how can i compile it for 32 bit then, any idea??
 
Old 05-24-2007, 04:34 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
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).
 
Old 05-25-2007, 03:34 AM   #5
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Original Poster
Rep: Reputation: 15
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

Last edited by kristof_v; 05-25-2007 at 03:42 AM.
 
Old 05-25-2007, 09:07 AM   #6
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Original Poster
Rep: Reputation: 15
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)
 
Old 05-25-2007, 02:28 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
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).
 
Old 05-29-2007, 03:33 AM   #8
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Original Poster
Rep: Reputation: 15
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
 
Old 05-29-2007, 04:47 AM   #9
kristof_v
Member
 
Registered: Feb 2006
Location: Belgium
Distribution: Debian
Posts: 84

Original Poster
Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Pascal question ascii2k Programming 8 11-04-2006 08:29 PM
Problem with Free Pascal ubuntuubuntu Linux - Software 4 02-28-2006 09:16 PM
Free Pascal ubuntuubuntu Linux - Software 2 02-23-2006 08:48 AM
LXer: Free Pascal speeding along LXer Syndicated Linux News 0 12-14-2005 03:31 AM
C Programming examples including linking with Pascal chris.hicks Programming 0 11-22-2003 04:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration