This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/24241] New: undefined reference to main when linking an object file generated from multiple .c files
- From: "indan at nul dot nu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Oct 2005 16:45:12 -0000
- Subject: [Bug c/24241] New: undefined reference to main when linking an object file generated from multiple .c files
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When making object files from multiple source files the main function seems to
be thrown away or something. When compiling the .c into .o files seperately,
and then linking that it works. It used to work with at least gcc 3.4.3.
Minimal testcase:
$ cat main.c
int main(void)
{
return 7;
}
$ make
cc -o test.o -c main.c empty.c
cc -s test.o -o test
/usr/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../crt1.o: In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [test] Error 1
$ objdump -t test.o
test.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 empty.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .comment 00000000 .comment
$ cat empty.c
$ cat Makefile
default: test
test.o: main.c empty.c
cc -o test.o -c main.c empty.c
clean:
rm -f *.o test
--
Summary: undefined reference to main when linking an object file
generated from multiple .c files
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: indan at nul dot nu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24241