LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-15-2004, 11:13 AM   #1
chip1081
LQ Newbie
 
Registered: Oct 2004
Location: Maryland
Posts: 2

Rep: Reputation: 0
Unhappy Problems with GNU linker ld


I am trying to compile some C code using GNU tools, gcc and ld. I have created a makefile and compiled my soruces to .o successfully. I then linked the object files to a executable file and seems to work. WHen I try to run the executable file I get an error message - /usr/lib/libc.o.1:Bad ELF interpreter: No such file or directory. The error message is correct, there is no /usr/lib/libc.o.1 file. In my makefile, in the line to link (ld) I have the option -lc. Remove this and I cannot compile due to the linker not finding the lib files for items like malloc, send,put,etc. I have tried all different ways to make the linker find the correct lib files but with no success. DOes anybody know if this file /usr/lib/libc.o.1 is suppose to exist? I installed Red Hat Linux on my PC. Here is another issue. If I create 1 dummy C file, compile just that file, and link to an executable with -lc, I don't get the ELF error. This problem only happens when I link multipule object files.
Does anybody out there know anything about this? THis problems pertains to my job and I need to get this software working ASAP.
 
Old 10-15-2004, 11:53 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
well, I have a libc.so

just edit the MAKEFILE and make it libc.so OR libc.so.1
 
Old 10-15-2004, 12:14 PM   #3
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
gcc links to libc automatically for you

you need to show us exactly the commands you are using or show us the makefile
before we can know what is going on
 
Old 10-15-2004, 02:24 PM   #4
chip1081
LQ Newbie
 
Registered: Oct 2004
Location: Maryland
Posts: 2

Original Poster
Rep: Reputation: 0
Parts of my makefile that do the linking
FULLSIM: $(OBJFILES)
$(LD) -o FULLSIM -r ($LD_FILES)
$(LD) -o fullsim.out FULLSIM -lc

Just a simple snapshoot of my makefile Link portion
 
Old 10-15-2004, 04:41 PM   #5
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
i really can't make heads or tails out of that
but is there any reason you can't eliminate the -r relocatable option and just do
$(LD) -o FULLSIM ($LD_FILES) -lc
all in one line ?
or better yet as i said before if you just use gcc instead of ld all you need is
$(CC) (if that's gcc) and assuming ($LD_FILES) are object files compiled with gcc -c
if your programm contains any c++ code use g++ instead of gcc
$(CC) -o FULLSIM ($LD_FILES)
this will produce a properly linked executable

also with what you have there your executable in the end is fullsim.out not FULLSIM yes
if you are trying to run FULLSIM then the runtime trouble obvoiusly is it -r (is just partially linked)
might just reverse the two like


$(LD) -o fullsim.out -r ($LD_FILES)
$(LD) -o FULLSIM fullsim.out -lc
 
Old 10-15-2004, 04:46 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Usually you just want to let gcc invoke ld for you. It automatically adds some extra command lineoptions that actually make things work correctly (I think if you invoke gcc in verbose mode, you can see what they are). Invoking ld by hand (rather than through gcc) is generally only done when you need to invoke some really special linker magic, or at least that's been my experience.
 
  


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
smtp problems on gnu linux 3.0 Descent Linux - Security 5 10-20-2005 12:48 PM
Linker problems daveyboy685 Programming 3 03-31-2005 05:08 PM
problems with linking objects -- must know some nasm\ASM\linker Paul6253 Programming 1 10-26-2004 08:33 PM
Linker problems on Mandrake 9.1 stodge Programming 0 05-07-2003 11:58 AM
GNU make problems MacDaddy Linux - General 9 08-26-2001 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:04 PM.

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