Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 148392 - make does not include .cpp file in $? every other compile when executeable exists
Summary: make does not include .cpp file in $? every other compile when executeable ex...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: Normal minor (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-20 09:31 UTC by Stephen E. Baker
Modified: 2006-09-20 10:51 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen E. Baker 2006-09-20 09:31:37 UTC
Sporatically when attempting to compile a C++ program I've been writing on GCC 4.1.1 I recieve an undefined reference to 'main' which seems to have nothing to do with my source code.  

The following two compiles were completed sequentially (the source code wasn't touched, no other programs were used).

stephen@sb03li /mnt/sandcastle/COSC5P71 $ make clean
rm *.o
stephen@sb03li /mnt/sandcastle/COSC5P71 $ make "CFLAGS= -Wall -O0 -g"
g++ -Wall -O0 -g -c Chromosome.cpp
g++ -Wall -O0 -g -c Random.cpp
g++ -Wall -O0 -g Chromosome.o Random.o -o kakuro
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../crt1.o: In function `_start':
init.c:(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [kakuro] Error 1
stephen@sb03li /mnt/sandcastle/COSC5P71 $ make clean
rm *.o
stephen@sb03li /mnt/sandcastle/COSC5P71 $ make "CFLAGS= -Wall -O0 -g"
g++ -Wall -O0 -g -c Chromosome.cpp
g++ -Wall -O0 -g -c Random.cpp
g++ -Wall -O0 -g Kakuro.cpp Chromosome.o Random.o -o kakuro
stephen@sb03li /mnt/sandcastle/COSC5P71 $ 

If only the executeable is deleted the compile seems to always succeed regardless of wether the object files were from a failed or successful compile, and optimization flags don't appear to make a difference.

My make file:
CC=g++
CFLAGS= -O2

all: kakuro

kakuro: Kakuro.cpp Chromosome.o Random.o
        $(CC) $(CFLAGS) $? -o $@

Chromosome.o: Chromosome.cpp
        $(CC) $(CFLAGS) -c $?

Random.o: Random.cpp
        $(CC) $(CFLAGS) -c $?

clean:
        rm *.o


This is on a Pentium 4 machine.
Comment 1 Stephen E. Baker 2006-09-20 09:50:53 UTC
Looking more carefully, every other time Kakuro.cpp is not included in the $?.  This only happens when the binary already exists, so the problem can be worked around by adding rm kakuro to make clean.  However, when the binary exists it happens every other time, which seems like unusual and undesirable behavior.


Comment 2 SpanKY gentoo-dev 2006-09-20 10:51:38 UTC
http://www.gnu.org/software/make/manual/make.html#Automatic-Variables

$?
    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).