With a RaspBerry Pi and from my computer, I'm trying to cross-compile a simple helloWorld written in C++. I'm using Code Sourcery toolchain for linux to compile.
When copy the helloWorld binary to raspBerry by TFTP and give it execution permissions with chmod, the next error appears:
"Illegal instruction"
If make a 'file' over binary I get:
"raspberry: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped"
This is because I used "-static -static-libstdc++" when linking.
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. 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).
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).
Another possible reason why you may be getting Illegal Instruction error is Code Sourcery cross-toolchain configured for ARMv7 and Raspberry Pi is 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. Resulting cross-compiler supports C++ and does not depend on cygwin runtime library (cygwin1.dll).
The problem was to use ASCII mode instead of binary mode in my FTP transfers.
Today I prefer to use SFTP (SSH).
Thanks.
I'd recommend trying biicode, it automatically sets up the cross compiler environment for you and sends generated binaries to the raspberry after building
You could try the toolchain at: 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. I'm using it to cross compile c++11 for a raspberrian target.
Please note it only works on linux x86_64 hosts.
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. Check it out.
Using Visual studio and Visual GDB plugin you can download cross compiler for raspberry pi. After that you can create a ssh connection and also you can deploy your program remotely into raspberry pi.
Related
I have MacBook Air with m1 chip and tried to install SFML according to the instructions on the official website however I can not compile the project for example
enter image description here
EDIT: I moved the Xcode app act via rosetta 2 and now it works I would love to know if there is a solution that will activate it natively
The error you are receiving is telling you that the version being linked is for MacOS on x32_64, while trying to compile for arm64. This is incompatible, given they're two different platforms.
Are you compiling SFML from source? It doesn't look like SFML has precompiled binaries for MacOS-arm64, but the source code does have arm compatibility. Compiling from source would be operating system agnostic as long as everything is there (and supports arm64.) SFML has an article on how to compile from source with CMake: https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php
While I can't guarantee this will fix your issue, it's definitely worth a try if you haven't yet.
The reason using Rosetta made this work is because Rosetta emulates some parts of x32_64. Running these apps in Rosetta would essentially be the same as compiling your project on an Intel based Mac.
I found the solution if it can help some, just make your pc believe that you have an intel chip, by adding /usr/bin/arch -x86_64 before your order.
example:
/usr/bin/arch -x86_64 clang main.c -lcsfml-graphics -lcsfml-system
15.09 does build fine on my normal linux system (ubuntu 64bit 14.04).
When trying to build Alljoyn 15.09a on my raspberry pi b+
using
scons CPU=arm OE_BASE=/usr CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- BINDINGS=cpp BT=off ICE=off WS=off
the build stops with with a linker error when linking alljoyn/test/proptester
anyone else encountering this?
15.04 builds fine on the pi.
15.09 fails the same way.
Is there a way to disable building the test programs?
Only thing I saw inside the bug tracker that might be related is:
https://jira.allseenalliance.org/browse/ASACORE-2642
I am attempting to port an application to an arm processor and have run into a roadblock. I don't get to change the source code and it uses a feature that is not available in the arm runtime on the arm host. I get the message on the arm host:
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version 'CXXABI_1.3.8' not found (required by MyDaemon);
I ran
strings libstdc++.so.6 | grep CXXABI and got the list with the last element as CXXABI_1.3.6.
Can I simply replace the toolchain/runtime on the arm machine or do I have to worry about other programs that link to it and will not run any longer?
g++ --version gives (Debian 4.6.3-14) 4.6.3
so maybe I can use a 4.9 toolchain and runtime?
The issue with that answer is that when the different libstdc++ is loaded it reports.
GLIBC_2.17 not found
The problem is that the environment on the machine where the application is compiled is different from the environment where the application is run and would like to know where to read to be able to solve this problem.
Recently, I got a new raspberry pi, and I want to use Eclipse on Windows with MinGW compiler to build c++ codes and run them on the raspberry pi. Is there any way to do that?
You need Cross-Compilation. When you create a project you need to Select the Cross GCC Toolchain and you need to set the Cross compile prefix to: "arm-linux-gnueabihf-"
Tutorial
I am having a problem with cross compiling google v8 libraries for raspberry pi, and constantly getting "Illegal instruction" error when compiling official sample from site. These are the steps i followed:
Downloaded cross compile https://github.com/raspberrypi/tools/
Cloned v8 git https://chromium.googlesource.com/v8/v8.git
Exported CXX LINK point to arm-linux-gnueabihf-g++ from cross compile tools.
run make arm.release armv7=false hardfp=on snapshot=off armfpu=vfp armfloatabi=hard -j5
Copied generated executable shell and d8 from out/arm.release directory to pi (Raspbian kernel version 3.6.11) and it WORKS.
These steps prove that cross compilation toolchain is functional.
Problem occurs when trying to run other cross-compiled software that is linked to v8 libraries. For example sample code from https://developers.google.com/v8/get_started#intro.
Code is cross-compiled with this command (same as example, just changed compiler)
arm-linux-gnueabihf-g++ -I. hello_world.cc -o hello_world -Wl,--start-group out/x64.release/obj.target/{tools/gyp/libv8_{base,libbase,snapshot,libplatform},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -pthread
When i copy that code to pi and run it i get SIGILL (Illegal instruction).
Note: cross compiled software that doesn't use v8 libraries works fine. Also x64 v8 libraries on host computer work fine.
On newer kernel versions shell and d8 were also throwing SIGILL but than i switched to older version 3.6.11 (problems with newer kernel https://groups.google.com/forum/#!topic/v8-users/IPT9EeYK9bg) and they started working, but compiled sample code is still showed same issues.
Did anyone have similar experience? Any suggestion on how to overcome this problem?
I found a solution thanks to post on v8 google group. https://groups.google.com/forum/#!topic/v8-users/LTppUbqNrzI
Problem was in make arguments it should be.
make arm arm_version=6 armfpu=vfp armfloatabi=hard