Quote:
Originally Posted by
meili100
Aha, I tried with cc -S main.i main.s
Now the main.s contains assemble instructions.
But after as -o main.o main.s
I use ld to link it: ld -o main main.o
the system reports:
$ ld -o main main.o
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
main.o(.text+0x15):main.c: undefined reference to `_alloca'
main.o(.text+0x1a):main.c: undefined reference to `__main'
main.o(.text+0x26):main.c: undefined reference to `malloc'
main.o(.text+0x5d):main.c: undefined reference to `printf'
That's wierd. Any clue?
This sounds like a link library issue, as a result of troubled gcc installation on cygwin.
_alloca is defined in libgcc.a.
__main is defined in libc.a
So, to solve these linker errors, you would need to explicity specify the link libraries such as libgcc.a and libc.a
This is how you do it :
In your makefile define variable LIBS and LIBDIR. Set the LIBDIR to point to where the library files are.
LIBS = $(LIBDIR)/libgcc.a $(LIBDIR)/libstdc++.a /lib/libc.a
Now include the $(LIBS) in the linker command.
$(PROJECT).bin: $(OBJECTS)
$(LD) -M -nostartfiles -nodefaultlibs -T $(LINK_FILE) -o \
$(PROJECT).bin $(OBJECTS) $(LIBS) > $(PROJECT).map
This should resolve the issue.