通用ELF(EM:40)

我想交叉编译forms的Ubuntu到友好的arm,但我得到了奇怪的错误:

root@kevin-VirtualBox:/home/kevin/Desktop/makef# make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-l gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt /usr/bin/ld: obj/main.o: Relocations in generic ELF (EM: 40) obj/main.o: could not read symbols: File in wrong format collect2: ld returned 1 exit status make: *** [main] Error 1 

命令行:make ARCH = arm CROSS_COMPILE = arm-none-linux-gnueabi-l

Makefile:(更新)

 export ARCH:=arm export CROSS_COMPILE:=arm-none-linux-gnueabi IDIR =./ CC=arm-linux-gnueabi-gcc CFLAGS=-I$(IDIR) LD= //opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/bin/ ODIR=obj LDIR =./ LIBS=-lgd -lrt _DEPS = main.h Makefile DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ = main.o serial.o fb.o menu_main.o timer.o cmdin.o buzzer.o statemachine.o inout.o network.o text_file_input.o text_file_input_oven.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) $(ODIR)/%.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) main: $(OBJ) $(CC) -o $@ $^ $(CFLAGS) $(LIBS) .PHONY: clean clean: rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 

更新Makefile后出现新错误:

 root@kevin-VirtualBox:/home/kevin/Desktop/makef# make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi -l gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt /usr/bin/ld: obj/main.o: Relocations in generic ELF (EM: 40) obj/main.o: could not read symbols: File in wrong format collect2: ld returned 1 exit status make: [main] Error 1 (ignored) arm-linux-gnueabi-gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: libz.so.1, needed by /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so, not found (try using -rpath or -rpath-link) /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: libexpat.so.1, needed by /usr/arm-linux-gnueabi/lib/libfontconfig.so.1, not found (try using -rpath or -rpath-link) /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetBuffer' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetErrorCode' /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so: undefined reference to `compress' /usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflate' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetDoctypeDeclHandler' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParserCreate' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `crc32' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetCurrentLineNumber' /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so: undefined reference to `uncompress' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateReset' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflate' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetCharacterDataHandler' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParserFree' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetUserData' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateInit2_' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParseBuffer' /usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateEnd' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateEnd' /usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `inflateInit_' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ErrorString' /usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetElementHandler' /usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateInit2_' /usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateReset' collect2: ld returned 1 exit status make: *** [main] Error 1 root@kevin-VirtualBox:/home/kevin/Desktop/makef# 

生成文件工作后,你的评论(谢谢),并创build一个主文件唯一的错误即时通讯: 警告:格式不是string文字和格式参数[-Wformat-security],但它dossent似乎是至关重要的

正如所写的,这个Makefile是用于交叉编译的,它不会一直使用$(CC)变量,所以它不能编译到非本地体系结构。

为了解决这个问题,把cc改为$(CC)

  main: $(OBJ) - gcc -o $@ $^ $(CFLAGS) $(LIBS) + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) 

它看起来像你以前试图用不同的工具链(如x86)进行编译,目标文件仍然是从那个版本。

尝试使用

  make clean 

我有一个类似的问题,干净没有帮助。 我结束了删除生成文件夹和重建,它的工作。