简体   繁体   English

RaspBerry Pi的交叉编译

[英]Cross-Compiling for RaspBerry Pi

With a RaspBerry Pi and from my computer, I'm trying to cross-compile a simple helloWorld written in C++. 使用RaspBerry Pi和我的计算机,我正在尝试交叉编译一个用C ++编写的简单helloWorld。 I'm using Code Sourcery toolchain for linux to compile. 我正在使用Code Sourcery工具链进行linux编译。

When copy the helloWorld binary to raspBerry by TFTP and give it execution permissions with chmod, the next error appears: 通过TFTP将helloWorld二进制文件复制到raspBerry并使用chmod赋予它执行权限时,会出现下一个错误:

"Illegal instruction" “非法指导”

If make a 'file' over binary I get: "raspberry: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped" 如果在二进制文件上创建'文件',我会得到:“raspberry:ELF 32位LSB可执行文件,ARM,版本1(SYSV),静态链接,剥离”

This is because I used "-static -static-libstdc++" when linking. 这是因为我在链接时使用了“-static -static-libstdc ++”。

If I don't use static linking, the error is: "Segmentation fault" 如果我不使用静态链接,则错误为:“分段错误”

The Code: 代码:

/*
 * main.cpp
 *
 *  Created on: 26/06/2012
 *      Author: ccortiz
 */

#include <iostream>
using namespace std;

int main(void){

    cout << "Hello Cross Compilling for ARM!" << endl << flush;
    return 0;
}

How could I compile and run my program in a right way? 我怎么能以正确的方式编译和运行我的程序? Thanks. 谢谢。

The reason why are you getting Segmentation fault error is different ABI. 你得到Segmentation fault错误的原因是ABI不同。 Raspberry Pi when running Raspbian is using linux-arm-gnueabihf ABI which assumes hardfp and VFP support in hardware (which is rare in ARMv6 environment) so requires some additional patches for GCC and EGLIBC (these patches can be found in Raspbian repository). Raspberry Pi在运行Raspbian时使用的是linux-arm-gnueabihf ABI,它假设硬件支持hardfp和VFP(这在ARMv6环境中很少见),因此需要为GCC和EGLIBC提供一些额外的补丁(这些补丁可以在Raspbian存储库中找到)。

Your Code Sourcery cross-toolchain most likely does not have these patches, so it's using another ABI ( linux-arm-gnueabi ) hence the crash at runtime (static linking works because kernel ABI does not depend on hardfp/softfp). 您的Code Sourcery交叉工具链很可能没有这些补丁,因此它使用另一个ABI( linux-arm-gnueabi )因此在运行时崩溃(静态链接起作用,因为内核ABI不依赖于hardfp / softfp)。

Another possible reason why you may be getting Illegal Instruction error is Code Sourcery cross-toolchain configured for ARMv7 and Raspberry Pi is ARMv6. 您可能会收到Illegal Instruction错误的另一个可能原因是为源代码工程师配置了ARMv7和Raspberry Pi的跨工具链是ARMv6。 But in this case both static and dynamic linking will yield the same error. 但在这种情况下,静态和动态链接都会产生相同的错误。

Here is a step-by-step guide how to build Raspberry Pi cross compiler in Windows , both hardfp/softfp ABI versions. 以下是如何在Windows中构建Raspberry Pi交叉编译器的逐步指南 ,两者都是hardfp / softfp ABI版本。 Resulting cross-compiler supports C++ and does not depend on cygwin runtime library (cygwin1.dll). 结果交叉编译器支持C ++,不依赖于cygwin运行时库(cygwin1.dll)。

我建议尝试使用biicode ,它会自动为您设置交叉编译环境,并在构建后将生成的二进制文件发送到树莓

The problem was to use ASCII mode instead of binary mode in my FTP transfers. 问题是在我的FTP传输中使用ASCII模式而不是二进制模式。 Today I prefer to use SFTP (SSH). 今天我更喜欢使用SFTP(SSH)。 Thanks. 谢谢。

You could try the toolchain at: https://github.com/kallaballa/Raspberry-GCC-4.7.3 您可以在以下网址尝试工具链: https//github.com/kallaballa/Raspberry-GCC-4.7.3

It's a pre-built gcc-4.7.3 toolchain for armv6 with hardfp using gnueabi. 它是armv6的预制gcc-4.7.3工具链,带有使用gnueabi的hardfp。 I'm using it to cross compile c++11 for a raspberrian target. 我正在使用它来交叉编译c ++ 11以获得raspberrian目标。

Please note it only works on linux x86_64 hosts. 请注意它只适用于linux x86_64主机。

My recommendation is here, http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/ He does a good job on explaining how to use Eclipse to compile HelloWorld.cpp, download, and execute it in Raspberry pi board. 我的建议在这里, http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/他在解释如何使用Eclipse编译HelloWorld.cpp方面做得很好,下载,并在Raspberry pi板中执行它。 Check it out. 看看这个。

Using Visual studio and Visual GDB plugin you can download cross compiler for raspberry pi. 使用Visual Studio和Visual GDB插件,您可以下载用于raspberry pi的交叉编译器。 After that you can create a ssh connection and also you can deploy your program remotely into raspberry pi. 之后,您可以创建一个ssh连接,也可以将程序远程部署到raspberry pi中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM