LinuxQuestions.org
Review your favorite Linux distribution.
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-18-2002, 12:15 PM   #1
gluon
Member
 
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 !) :

/*a.h*/
int func_a ();

/*a.c*/
#include "a.h"
int func_a ()
{
return 5;
}

/*b.h*/
int func_b ();

/*b.c*/
#include "b.h"
int func_b ()
{
return 10 * 10;
}

/*main2.c*/
#include <stdio.h>
#include "a.h"
#include "b.h"

int
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 !!!

Gluon

Last edited by gluon; 05-18-2002 at 12:22 PM.
 
Old 05-18-2002, 01:39 PM   #2
Config
Member
 
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
kervin
Member
 
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 )

--Kervin
 
  


Reply


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 08:14 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration