Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-18-2002, 12:15 PM   #1
Registered: Jun 2001
Location: Switzerland
Distribution: SuSE 8.[012], Gentoo
Posts: 42

Rep: Reputation: 15
Question linking problem with ld !

Hi all,

I'm working on my diploma work (subject : Efficiency of the GNU tool in a professional project !!!). I'm exploring the binutils' tools, gcc, others...
But I have a problem : I'd like to link a program with ld instead of gcc. Here are the progs (examples !) :

int func_a ();

#include "a.h"
int func_a ()
return 5;

int func_b ();

#include "b.h"
int func_b ()
return 10 * 10;

#include <stdio.h>
#include "a.h"
#include "b.h"

main(int argc, char* argv[])
int a = func_a();
int b = func_b();
char c;
char* bc = &c;

printf("hello world,\n");
printf("a - %d; b - %d;\n", a, b);

return 0;

If I do a normal compilation with gcc, by
gcc -c a.c b.c ; gcc -o prog a.o b.o main2.c
it produces an execuable, which runs perfectly well (ok, it's a stupid prog !!!)

Now I'd like to link everything with ld :
gcc -c *.c
ld -L./ a.o b.o main2.o -o prog -lc
ld gives a warning :
ld: warning: cannot find entry symbol _start; defaulting to 08048190
Nevertheless, an executable has been produced, but if I execute it :
bash: ./prog: No such file or directory

I've searched the web for an explanation, but I didn't find anything interesting ! Could anyone help me or give me an address where I could find a way of doing this linking ?

Thanks in advance !!!


Last edited by gluon; 05-18-2002 at 12:22 PM.
Old 05-18-2002, 01:39 PM   #2
Registered: Jan 2001
Location: Switzerland
Distribution: Gentoo
Posts: 376

Rep: Reputation: 30
I really have no idea, but i suspect that you have to put a switch for the gcc command.
As for the No such file or directory:
May be, ld hasn't set the executable bit yet so type: chmod +x prog

Hope this helps! Good luck!
Old 05-19-2002, 02:59 PM   #3
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
gcc adds libraries for you by default. If you link with ld, then you need to specify these libraries explicitly.

do a 'gcc -v -o prog a.o b.o main2.c' to see what ld libraries are being linked for your platform. I believe you are at least missing the C runtime ( crt )



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Linking Problem I think? gplacek Linux - Software 10 08-13-2004 08:01 PM
ld linking problem captain-mythos Linux - Software 1 06-20-2004 09:46 AM
Library linking problem The_Nerd Programming 10 04-27-2004 12:07 AM
C++ Linking Problem acjt Programming 4 01-31-2004 09:48 AM
Problem linking Red Guy Programming 1 02-07-2003 04:52 AM

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

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