gpt4 book ai didi

c++ - 交叉编译 C++ 项目,通用 ELF 中的重定位 (EM : 3)

转载 作者:可可西里 更新时间:2023-11-01 17:39:32 25 4
gpt4 key购买 nike

我从事 C++ 项目已有一段时间了,但想将其移植到我的 arm 处理器上。我已经有了我所有的交叉编译工具(我正在使用 CodeSourcery),我想我可以更改我的 makefile 以指向该编译器。它使用默认的 g++ 编译得很好,但是当尝试 make 指向交叉编译器时,我得到重定位错误:

/home/oryan/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/bin/ld: ServerSocket.o: Relocations in generic ELF (EM: 3)
ServerSocket.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [simple_server] Error 1

我似乎没有设置正确的链接,或者它指向了错误的位置。我对 makefile 不太熟悉,可能遗漏了一些明显的东西。我一直在使用的 makefile 来自 http://tldp.org/LDP/LG/issue74/tougher.html删除客户端:

# Makefile for the socket programming example
#

simple_server_objects = ServerSocket.o Socket.o simple_server_main.o

all : simple_server

simple_server: $(simple_server_objects)
/home/matt/CodeSourcery/bin/arm-none-linux-gnueabi-g++ -o simple_server $(simple_server_objects)


Socket: Socket.cpp
ServerSocket: ServerSocket.cpp
simple_server_main: simple_server_main.cpp

clean:
rm -f *.o simple_server

现在我正在手动编译每个文件并且效果很好,但我想在这里进一步了解。

谢谢!

最佳答案

问题是您已经将您的 makefile 设置为与新的 g++ 链接,但您还没有更改用于首先构建对象的编译器。

解决此问题的最简单方法是将环境 CXX 设置为下一个编译器,即

export CXX=/home/matt/CodeSourcery/bin/arm-none-linux-gnueabi-g++

或者通过将 CXX=... 添加到命令行来为给定的 make 设置它。

您需要先make clean,然后您将使用正确的编译器进行编译和链接。

您还可以在 makefile 中指定一个新的 how-to-compile-C++ 文件规则来指定新的编译器,但环境变量更容易:

.cc.o:
/home/.../g++ $(CPPFLAGS) $(CXXFLAGS) -c

关于c++ - 交叉编译 C++ 项目,通用 ELF 中的重定位 (EM : 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8168950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com