交叉编译C ++项目,通用ELF中的重定位(EM:3) [英] Cross compiling C++ project, Relocations in generic ELF (EM: 3)

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

问题描述

我已经在c ++项目上工作了一段时间,但想将其移植到我的ARM处理器上.我已经拥有了所有的交叉编译工具(我正在使用CodeSourcery),并认为我可以更改我的makefile使其指向该编译器.使用默认的g ++可以很好地进行编译,但是当尝试使用指向交叉编译器的make时,会出现重定位错误:

I've been working on a c++ project for a while now, but would like to port it over to my arm processor. I already have all of my cross-compile tools (I'm using CodeSourcery) and thought I could just change my makefile to point to that compiler. It compiles fine using the default g++, but When try a make pointing to the cross-compiler I get relocation errors:

/home/oryan/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm/none-linux-gnueabi/bin/ld:ServerSocket.o:通用ELF(EM:3)中的重定位
ServerSocket.o:无法读取符号:文件格式错误
collect2:ld返回1退出状态
make:*** [simple_server]错误1

/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 :

It seems like I don't have a proper link set up or it's pointing to a wrong location. I'm not that familiar with makefiles and am probably missing something obvious. The makefile I've been using is from http://tldp.org/LDP/LG/issue74/tougher.html with the client side removed:

# 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

目前,我正在手动编译每个文件,并且效果很好,但是我想在这里进一步加深理解.

Right now I am manually compiling each file and it works great, but I'd like to further my understanding here.

谢谢!

推荐答案

问题是您已将makefile设置为与新g ++链接,但尚未更改用于在其中构建对象的编译器第一名.

The problem is you've set your makefile up to link with the new g++ but you haven't changed the compiler you're using to build the objects in the first place.

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

The easiest way to fix this is to set environment CXX to the next compiler, i.e.

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

或通过在命令行中添加 CXX = ... 来为给定的 make 进行设置.

or just set it for a given make by adding CXX=... to the command line.

您需要先进行 clean 的操作,然后再使用正确的编译器进行编译和链接.

You'll need to make clean first but you'll then use the correct compiler for both the compile and link.

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

You could also specify a new how-to-compile-C++ files rule in your makefile to specify the new compiler but the environment variable is easier:

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

这篇关于交叉编译C ++项目,通用ELF中的重定位(EM:3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆