【问题标题】:Relocations in generic ELF (EM: 40)通用 ELF 中的重定位 (EM: 40)
【发布时间】:2017-02-01 02:34:09
【问题描述】:

我试图从 Ubuntu 交叉编译到 Friendly-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# 

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

【问题讨论】:

  • 您现在(截至 18:50)发布的输出与您的 Makefile 不匹配。
  • 输出表明编译器运行了两次,一次是gcc(或者可能是cc),第二次是arm-linux-gnueabi-gcc。这对于您问题中的 Makefile 版本是不可能的。

标签: c++ linux arm cross-compiling


【解决方案1】:

正如所写,此 Makefile 无法进行交叉编译 - 它没有始终如一地使用 $(CC) 变量,因此无法编译为非本地架构。

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

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

【讨论】:

  • 更新 makefile 后出现一些其他错误
  • -+ 旨在作为补丁指示符,而不是作为 Makefile 中的文字文本。涉及 libz 和 libexpat 的错误似乎表明您没有为交叉编译系统正确安装这些库。
  • @kevinver 您现在发布的错误是链接器错误,您似乎使用了必须链接到的各种库,例如libz、libpng 和 libxml2 以及其他可能。 (你可能还需要先交叉编译这些)
  • 我也遇到了类似的问题,我用这里的想法解决了这个问题。我使用用于交叉编译的 $(CXX) 在 .a 中编译了 .o 文件,但使用 gcc 编译了主程序的 .o。难怪库不能链接到主程序。他们有不同的目标环境设置。我在主程序和链接命令的编译命令中将gcc更改为$(CXX),它可以工作。
【解决方案2】:

看起来您以前尝试过使用不同的工具链(例如 x86)进行编译,并且该构建中的目标文件仍然存在。

尝试使用

 make clean

【讨论】:

  • make clean 返回 'rm -f obj/*.o *~ core /*~ ' 并删除所有 .o 文件。当我运行 make 我得到同样的错误
  • 啊,是的,我注意到@duskwuff 发现了另一个问题 - 它是相同的“错误类型”(混合工具),但由不同的场景引起。
  • 根据@duskwuff 的建议更新了问题
  • 看起来你缺少一些库(某种压缩/解压缩库 - 不确定是 libz 还是其他 - 以及一些 XML 库)。
【解决方案3】:

我遇到了类似的问题,而 clean 没有帮助。我最终删除了构建文件夹并重新构建,它起作用了。

【讨论】:

    猜你喜欢
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 2010-11-23
    • 1970-01-01
    • 2013-06-20
    • 2014-12-21
    • 2011-10-14
    相关资源
    最近更新 更多