Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-22-2007, 06:21 AM   #1
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
Question ld : warnings and errors


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;
return 0;

SRC= temp.c
OBJ= temp.o


all: Check

Check: $(SRC)
gcc $(CFLAGS) $(SRC)
ld -o check $(OBJ)
-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?

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

Rep: Reputation: 15
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.):

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
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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:
CC = gcc

OBJECTS = temp.o

        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():
#include <stdio.h>

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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 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