Results 1 to 10 of 17
I am using Cygwin and trying to cross compile a program with gcc, but get these "undefined reference" errors for many functions. They all seem to be stdio.h functions, but ...
- 08-11-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 27
Undefined reference?
I am using Cygwin and trying to cross compile a program with gcc, but get these "undefined reference" errors for many functions. They all seem to be stdio.h functions, but I am not getting an error saying stdio.h is not found, so maybe its something within that is corrupt? Any help is appreciated!
Errors:
Code:XXXXXX.o: In function `XXXXXX': /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:470: undefined reference to `fgets' XXXXXX.o: In function `main': /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:161: undefined reference to `fseek' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:174: undefined reference to `strtod' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:161: undefined reference to `fseek' XXXXXX.o: In function `XXXXXX': /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:577: undefined reference to `memcpy' XXXXXX.o: In function `XXXXXX': /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:397: undefined reference to `sscanf' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:400: undefined reference to `__ctype_ptr' XXXXXX.o: In function `XXXXXX': /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:491: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:494: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:513: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:514: undefined reference to `sscanf' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:519: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:541: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:532: undefined reference to `sscanf' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:504: undefined reference to `sscanf' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:513: undefined reference to `__ctype_ptr' /cygdrive/c/XXXXXX/XXXXXX/GNU/XXXXXX_GNU/XXXXXX/build/../XXXXXX.c:537: undefined reference to `memcpy'
Possibly it's an error in my makefile??
Makefile:
Code:bin_PROGRAMS = File1 \ File1.chksum.elf \ File1.y16 SOURCE_DIR = $(top_srcdir) SOURCE_SRC_DIR = $(SOURCE_DIR) SOURCE_INCLUDE_DIR = /../include SOURCE_COMMON_DIR = $(SOURCE_DIR)/../common SOURCE_LDSCRIPT_DIR = $(SOURCE_DIR) SOURCE_PROM_DIR = $(SOURCE_DIR) SOURCE_DOC_DIR = $(SOURCE_DIR)/doc SOURCE_DOC_NOTES_DIR = $(SOURCE_DOC_DIR)/notes SOURCE_DOC_EXAMPLES_DIR = $(SOURCE_DOC_DIR)/examples BUILD_DIR = $(top_builddir) BUILD_SRC_DIR = $(BUILD_DIR) ##Line 23 BUILD_PROM_DIR = $(BUILD_DIR) BUILD_DOC_DIR = $(BUILD_DIR)/doc #List of files that are sources to File1.exe File1_SOURCES = File1Main.c \ File2.c \ File3.c \ File4.c \ File5.c \ File6.c \ File7.c \ $(SOURCE_COMMON_DIR)/File8.c \ $(SOURCE_COMMON_DIR)/File8Calls.s \ $(SOURCE_COMMON_DIR)/Cksum.s \ $(SOURCE_COMMON_DIR)/bits.s AM_CFLAGS=-O3 -Wno-main -fomit-frame-pointer -I$(SOURCE_INCLUDE_DIR) \ -m68000 $(DEBUG) \ -Wa,-alh="$(BUILD_PROM_DIR)/`echo "$@" | sed -e "s/\.$(OBJEXT)/\.lst/g"`",-L AM_CCASFLAGS=$(AM_CFLAGS) #Linker Flags AM_LDFLAGS=-M -cref -File1 File1.File1 -T $(SOURCE_LDSCRIPT_DIR)/File1.ld -L`m68k-elf-gcc -m68000 --print-libgcc | sed -e "s/libgcc.a//g"` File1_LINK=m68k-elf-ld $(AM_LDFLAGS) -o $@ File1_LDADD=-lgcc M68K_SREC_CHKSUM = @M68K_SREC_CHKSUM@ .PHONY: File1.y16 File1.chksum.elf SUFFIXES = .y16 .elf File1.chksum.elf: File1 @ m68k-elf-objcopy \ --srec-len=14 \ -I elf32-m68k \ -O srec \ --set-start 0x0000 \ --change-section-address GPARMS=0x0000 \ --change-section-address APPLINIT=0x000c \ --change-section-address APPPROG=0x0100 \ --change-section-address .text=0x0100 \ --no-change-warnings \ --remove-section=APPDATA \ --remove-section=.bss \ --remove-section=COMMON \ $< \ $<.srec @ echo -n "File1.y16 : " > File1-checksums.txt @ $(M68K_SREC_CHKSUM) -T word-2s-comp-big -I $<.srec -A 0xFFFE -V 0xFFFF >> File1-checksums.txt @ echo "" >> File1-checksums.txt @ echo "unsigned short __attribute__ ((section (\".checksum\"))) checksum=`$(M68K_SREC_CHKSUM) -T word-2s-comp-big -I $<.srec -R -A 0xFFFE -V 0xFFFF`;" > gm-checksum.c @ echo "Building Application with Checksum" @ $(CC) $(CFLAGS) -c File1-checksum.c -o File1-checksum.o @ $(File1_LINK) $(File1_OBJECTS) File1-checksum.o $(File1_LDADD) File1.y16: File1.chksum.elf @ m68k-elf-objcopy \ --srec-len=14 \ --set-start 0x0000 \ --change-section-address GPARMS=0x0000 \ --change-section-address APPLINIT=0x000c \ --change-section-address APPPROG=0x0100 \ --change-section-address .text=0x0100 \ --change-section-address .checksum=0xFFFE \ --no-change-warnings \ --remove-section=APPDATA \ --remove-section=.bss \ --remove-section=COMMON \ -I elf32-m68k \ -O srec \ $< \ $@ @ m68k-elf-objcopy \ --srec-len=14 \ --set-start 0x0000 \ --change-section-address GPARMS=0x10000 \ --change-section-address APPLINIT=0x1000c \ --change-section-address APPPROG=0x10100 \ --change-section-address .text=0x10100 \ --change-section-address .checksum=0x1FFFE \ --no-change-warnings \ --remove-section=APPDATA \ --remove-section=.bss \ --remove-section=COMMON \ -I elf32-m68k \ -O srec \ $< \ ./tests/test.h68
- 08-11-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You are cross-compiling for a 68k chip? These unresolved references should be in libc, which it seems you are missing for the target platform. Also, you probably want to statically link your 68k system libraries.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 08-11-2009 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 27
Yes, I am cross compiling for a 68k. I looked up the references and they are all in stdio.h - newlib (what Cygwin uses instead of glibc). The makefile here was copied from another program that does the same thing for a smaller program, all I did was add to it, so I don't understand why I am getting all these errors.
What do you mean by statically linking my 68k system libraries?
Thanks
- 08-11-2009 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
SInce you are building 68k executables, you need to link 68k libraries to the executable. Statically linking them means you don't need shared libraries to run the executables (bigger size, less versionitis issues). Your linker specifies a directory for the mc68k libraries, but you don't tell it which libraries to link (-lc -lm etc).
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 08-11-2009 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 27
Please excuse my ignorance (I did not write these files), but aren't the following lines linking the libraries?:
Code:#Linker Flags AM_LDFLAGS=-M -cref -File1 File1.map -T $(SOURCE_LDSCRIPT_DIR)/File1.ld -L`m68k-elf-gcc -m68000 --print-libgcc | sed -e "s/libgcc.a//g"` File1_LINK=m68k-elf-ld $(AM_LDFLAGS) -o $@ File1_LDADD=-lgcc
- 08-11-2009 #6Just Joined!
- Join Date
- Jul 2009
- Posts
- 27
Update: I changed the line
AM_LDFLAGS=-M -cref -File1 File1.File1 -T $(SOURCE_LDSCRIPT_DIR)/File1.ld -L`m68k-elf-gcc -m68000 --print-libgcc | sed -e "s/libgcc.a//g"
to
AM_LDFLAGS=-M -cref -File1 File1.File1 -T $(SOURCE_LDSCRIPT_DIR)/File1.ld -L../../../../cygwin/opt/m68k/m68k-elf/lib -m68000 --print-libgcc | sed -e "s/libgcc.a//g"
And I no longer get the reference errors...just other ones.
- 08-11-2009 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
It depends on what the command
returns. The -L (capital ell) tells the compiler where to find libraries, not which ones to link. So, it is only linking libgcc which apparently doesn't include other library stuff, assuming it is there. Without looking at your cygwin system configuration and mc68k libraries, etc. I cannot tell you more than this. Simply put, you are missing references, so either you aren't linking the required libraries, or if the referenced symbols are in libgcc.a then you might need to link it twice in order to resolve recursive references. When linking an executable with static libraries (libgcc.a), the linker only makes one pass thru the library. If parts in the library require other parts in the same library that have already been scanned but not linked, or if some other component is linked after the library but requires parts in the library not already linked, then you need to add another -lgcc to the link arguments.Code:m68k-elf-gcc -m68000 --print-libgcc | sed -e "s/libgcc.a//g"
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 08-11-2009 #8
- 08-11-2009 #9Just Joined!
- Join Date
- Jul 2009
- Posts
- 27
This is my current output:
Code:make all-am make[1]: Entering directory `/cygdrive/c/XXXXX/XXXX/build' m68k-elf-ld -M -cref -File1 file1.map -T ../file1.ld -L../../../../cygwin/opt/m68k/m68k-elf/lib -m68000 --print-libgcc | sed -e "s/libgcc.a//g"` -o File1 File1Main.o File2.o File3.o File4.o File5.o File6.o File7.o File8.o File9.o File10.o File11.o File12.o File13.o -lgcc /bin/sh: -c: line 0: unexpected EOF while looking for matching ``' /bin/sh: -c: line 1: syntax error: unexpected end of file make[1]: *** [File1] Error 2 make[1]: Leaving directory `/cygdrive/c/XXXX/XXXX/build' make: *** [all] Error 2
- 08-11-2009 #10Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Actually, you probably should remove the section where you pipe the output of --print-gcc to sed. Ie,
I suspect you will continue to get the unresolved references. Look in the m68k-elf/lib directory and see what is there. If you see libc.a, try adding -lc after the -lgcc.Code:m68k-elf-ld -M -cref -File1 file1.map -T ../file1.ld -L../../../../cygwin/opt/m68k/m68k-elf/lib -m68000 -o File1 File1Main.o File2.o File3.o File4.o File5.o File6.o File7.o File8.o File9.o File10.o File11.o File12.o File13.o -lgcc
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
