PDA

View Full Version : Error of makefile


gold_marigold55
04-24-2005, 11:56 PM
Hi,

I wrote a makefile for compiling my c program, the file is as following:

/* begining */
sftp: main.o my_header.o connect.o
cc -o main.o my_header.o connect.o -lnsl -lsocket
main.o: main.c
cc -c main.c
my_header.o: my_header.c
cc -c my_header.c my_header.h
/* ended */

Please note that the main.c and my_header.c include my_header.h and I got the error as:

% make
cc -c main.c my_header.c
main.c:
my_header.c:
cc -o main.o my_header.o connect.o -lsocket -lnsl
Undefined first referenced
symbol in file
main /opt/SUNWspro/prod/lib/crt1.o
ld: fatal: Symbol referencing errors. No output written to main.o
make: *** [sftp] Error 1
%


Could u please tell me what this means? And how to fix it?

Also I don't know how to use "Code TAGS" to put my code in order more readable, where can I find instructions?

Thanks.

:confused: Gold_marigold

RobSeace
04-25-2005, 12:51 PM
[You can find help on how to use code tags right there in the message imploring
you to use them: it links to http://www.developerweb.net/forum/misc.php?do=bbcode#code...]

The error message sounds to me like you simply haven't defined a main() function...
The error has nothing to do with your makefile, but is coming from the linker... And,
it sure looks to me like it's complaining about not being able to find a main() to call...

gold_marigold55
04-26-2005, 01:30 AM
Hi administrators,

My program will compile if I issued the command as following:

cc -o sftp main.c my_header.c connect.o -lnsl -lsocket

By the way, how can I know what is the version of the compiler of my unix platform? This happened I compiled my program correctly but got fatal errors on unix.

Many thanks.

:-? gold_marigold

RobSeace
04-26-2005, 12:23 PM
Ah, yeah, your makefile IS wrong, indeed:


sftp: main.o my_header.o connect.o
cc -o main.o my_header.o connect.o -lnsl -lsocket


You are missing the "sftp" after the "-o" in that link line... So, you're really overwriting
"main.o" with the full executable contents, but then failing, because there's no main()
function anymore (since it was presumably in "main.o")...

As for determining compiler version, well that usually depends on the particular
compiler you're using... But, try "cc --version" or "cc -v"... Failing that, look through
the local man pages or other docs...