LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 01-22-2007, 06:21 AM   #1
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
Question ld : warnings and errors


Hi,

I have a simple .c file and a make file to compile it. But when i run make i am getting some warnings and errors.

My source file

#include <stdio.h>

int main()
{
int a = 0;
printf("%d\n",a);
return 0;
}


Makefile:
SRC= temp.c
OBJ= temp.o

CFLAGS = -c

all: Check

Check: $(SRC)
gcc $(CFLAGS) $(SRC)
ld -o check $(OBJ)
clean:
-rm -rf *o


I am getting following warnings and errors:
ld: warning: cannot find entry symbol _start; defaulting to 08048074
temp.o(.text+0x23): In function `main':
: undefined reference to `printf'
make: *** [dal] Error 1

Can any body tell me what is the problem?


Regards,
Karim
 
Old 01-22-2007, 06:57 AM   #2
KenJennings
LQ Newbie
 
Registered: Mar 2005
Location: FL, USA
Distribution: SuSE
Posts: 28

Rep: Reputation: 15
Quote:
Originally Posted by rajesh_b
[...]
I am getting following warnings and errors:
ld: warning: cannot find entry symbol _start; defaulting to 08048074
temp.o(.text+0x23): In function `main':
: undefined reference to `printf'
make: *** [dal] Error 1
Are you building this on unix? linux? what?

Is there a specific reason you need to use ld directly? gcc can invoke linking itself and quietly include necessary system object files. " gcc -o check temp.o " should work.

Man ld includes a simple example of invoking ld on a simple program (in a specific unix environment.):

Code:
The  linker  supports a plethora of command-line options, but in actual practice 
few of them are used in any particular context.  For instance, a frequent use of ld is 
to link standard Unix object files on a standard, supported  Unix  system.  On such a 
system, to link a file "hello.o":

               ld -o <output> /lib/crt0.o hello.o -lc
 
Old 01-22-2007, 07:50 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Please use [code] tags to improve reabaility of your posts.

Try a different Makefile. This one is quite nice and easy to maintain for small projects:
Code:
CC = gcc
CFLAGS = -g
LFLAGS =

OBJECTS = temp.o
EXECUTABLE = myprog

$(EXECUTABLE) : $(OBJECTS)
        gcc $(LFLAGS) $(OBJECTS) -o $@

clean :
        rm -f $(OBJECTS) $(EXECUTABLE)

%.o : %.c
        gcc -c $(CFLAGS) $< -o $@
As you add more sources, just add the names of the object files they will build to OBJECTS. he rest is automatic.

To prevent warnings, and to be standards compliant, don't forget to add the proper arguments to main():
Code:
#include <stdio.h>

int main(int argc, char** argv)
{
        int a = 0;
        printf("The number is %d\n",a);
        return 0;
}
 
  


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
Warnings treated as errors smallfire Fedora 4 07-17-2006 12:08 AM
Warnings treated as errors(help) smallfire Programming 12 07-17-2006 12:04 AM
Errors and warnings after logging out of KDE? Slovak Slackware 7 10-17-2005 04:56 AM
log warnings and errors - are these serious? bcal Fedora 3 02-12-2005 04:13 PM
Errors and warnings when I exit X cragwolf Slackware 5 09-01-2004 01:52 AM


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

Main Menu
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