You are not logged in.
Hi there!
I got a very strange message while compiling with make some files using ansi-C programming language:
This error occurs whenever i change or touch a source-code file, as you can see:
[quark@supernova p2]$ make clean
rm -f *.o *.gch core main
[quark@supernova p2]$ make
gcc -g -c cmds.c cmds.h
gcc -g -c sosh.c sosh.h
gcc -g -c main.c
gcc -o main cmds.o sosh.o main.o
[quark@supernova p2]$ make
make: `main' is up to date.
[quark@supernova p2]$ touch cmds.c
[quark@supernova p2]$ make
gcc -g -c cmds.c
gcc -o main cmds.o
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [main] Error 1
[quark@supernova p2]$ make
gcc -o main cmds.o sosh.o main.o
(and now it is compiled, after making twice)
I got the programs: ddd, kdbg, gdb installed.
Should I do a "make clean" before compile the whole code?
I just would like to know what to do to avoid "make" the project twice.
Thanks in advance.
edit:
here is my Makefile:
## Variables
cc=gcc
cflags=-g -c
out=main
## Makefile dependencies
main: cmds.o sosh.o main.o
$(cc) -o $@ $?
main.o: main.c
$(cc) $(cflags) $?
cmds.o: cmds.c cmds.h
$(cc) $(cflags) $?
sosh.o: sosh.c sosh.h
$(cc) $(cflags) $?
clean:
rm -f *.o *.gch core $(out)
Last edited by quarkup (2008-10-07 14:48:02)
If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.
Offline
here is my Makefile:
## Variables cc=gcc cflags=-g -c out=main ## Makefile dependencies main: cmds.o sosh.o main.o $(cc) -o $@ $?
I think the problem is $?, because:
$?:
The names of all the prerequisites that are newer than the target, with spaces between them. For prerequisites which are archive members, only the member named is used (see Archives).
http://www.gnu.org/software/make/manual … -Variables
$? feeds only the modified (newer) *.o files into gcc and thereby ommits some files that should be linked together.
Offline
Thanks, that's it!
I changed main to this
main: cmds.o sosh.o main.o
$(cc) -o $@ cmds.o sosh.o main.o
and replaced every '$?' by '$<'
Thank you, now it's working as it should.
If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.
Offline