本文介绍了通用 ELF 中的重定位(EM:40)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 Ubuntu 到 Friendly-arm 交叉编译,但出现奇怪的错误:

I trying to cross compile form Ubuntu to Friendly-arm but I'm getting the strange error:

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

command line : make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-l

Makefile:(更新)

Makefile: (updated)

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 后的新错误:

New errors after updating 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#

makefile 在您发表评论后工作(谢谢)并创建一个主文件,我得到的唯一错误是:警告:格式不是字符串文字并且没有格式参数 [-Wformat-security] 但是它似乎很重要

the makefile works after your comment (thank you) and creates a main file the only error im getting is : warning: format not a string literal and no format arguments [-Wformat-security] but it dossent seem to be critical

推荐答案

正如所写的,这个 Makefile 对于交叉编译是 BROKEN — 它没有一致地使用 $(CC) 变量,所以它无法编译为非本地架构.

As written, this Makefile is BROKEN for cross-compilation — it does not use the $(CC) variable consistently, so it cannot compile to a non-native architecture.

要修复它,请将 main 节中的 cc 更改为 $(CC),即:

To fix it, change cc to $(CC) in the stanza for main, i.e:

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

这篇关于通用 ELF 中的重定位(EM:40)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:45