gcc,raspberry-pi,cross-platform,raspbian , How can I create a modern cross compile toolchain for the Raspberry Pi 1?


How can I create a modern cross compile toolchain for the Raspberry Pi 1?

Question:

Tag: gcc,raspberry-pi,cross-platform,raspbian

At least Debian does not provide a usable toolchain to cross develop for the Raspberry Pi 1. The Linaro toochain is at the time of this writing too old for the Qt5 developer branch. There is a project crosstools-ng, which allows to easily build custom toolchains for all kinds of systems. It supports a fairly modern GCC 4.9.1. The configuration is a bit trial and error, but the main problem is, that the toolchain does not find all the include files or libraries. How is the crosstools-ng to be configured so it can be used to compile Qt5 for the Raspberry Pi 1?

A followup how a Raspberry Pi with Raspian has to be prepared to use this toolchain can be found here: How do I prepare a Raspberry Pi with Raspian so I can cross compile Qt5 program from a Linux host?


Answer:

I start with the not found include/library problem first, since this goes a bit beyond the normal crosstools-ng installation/usage.

The problem is, that crosstools-ng rightfully creates gcc compiler, with a target tuple like: arm-vendor-linux-gnueabihf. This is totally correct. However, Raspian installs includes and libs in folders without vendor string: /lib/arm-linux-gnueabihf. Looks like pkg-config cannot handle this. crosstools-ng might be right with the tuple, but is also a bit heavy handed by refusing to add a function to remove this vendor string. The functions in crosstool-ng, which allow to modify the tuple and the vendor string are not an alternative. They just create symbolic links with a new name, but the tuple is hardcoded in GCC. The only way to properly get rid of the vendor string is to patch the crosstools-ng sources.

So the first step to get a functional Raspberry Pi/Raspian gcc 4.9.1 toolchain is to clone the crosstools-ng repository:

git clone git://crosstool-ng.org/crosstool-ng

Second is to patch sources:

diff --git a/scripts/config.guess b/scripts/config.guess
index dbfb978..9a35943 100755
--- a/scripts/config.guess
+++ b/scripts/config.guess
@@ -176,7 +176,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
            sh3el) machine=shl-unknown ;;
            sh3eb) machine=sh-unknown ;;
            sh5el) machine=sh5le-unknown ;;
-           *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+           *) machine=${UNAME_MACHINE_ARCH} ;;
        esac
        # The Operating System including object format, if it has switched
        # to ELF recently, or will in the future.
diff --git a/scripts/config.sub b/scripts/config.sub
index 6d2e94c..f92db2b 100755
--- a/scripts/config.sub
+++ b/scripts/config.sub
@@ -317,7 +317,7 @@ case $basic_machine in
        | we32k \
        | x86 | xc16x | xstormy16 | xtensa \
        | z8k | z80)
-               basic_machine=$basic_machine-unknown
+               basic_machine=$basic_machine
                ;;
        c54x)
                basic_machine=tic54x-unknown

The rest is the standard configure/make/make install. The next step is to configure crosstools-ng correctly to build the desired toolchain. This is done with ct-ng menuconfig.

Going though every single config item would be extremely lengthy, so I added a working config file here: http://pastebin.com/MhQKnhpN

It can be imported and with Load an Alternate Configuration File. Finally ct-ng build builds in a few minutes a new toolchain. The toolchain is created in {HOME}/x-tools3, as defined in the config file. To change this, change 'Prefix directory' in 'Path and misc options'. But the toolchain can also be moved manually after the build.

The next question/answer will show how to use this toolchain to build a very modern Qt5 for the Raspberry Pi.


Related:


using ‘-Wcast-qual’ option to check the compilation


c,gcc
I am reading an introduction to gcc in which it says: ‘-Wcast-qual’ this option warns about pointers that are cast to remove a type qualifier, such as const. For example, the following function discards the const qualifier from its input argument, allowing it to be overwritten: void f (const char...

Checking all elements of array for a logical condition in fortran


gcc,fortran,gfortran
I want to check all rows of an array for a logical condition. I used function ALL as described in GNU GCC guide https://gcc.gnu.org/onlinedocs/gfortran/ALL.html Here is a sample code: program test3 implicit none real, allocatable, dimension (:,:) :: mat1 integer :: i,j,k,r logical :: lg r=3 allocate(mat1(r,r)) mat1=transpose( reshape( (/-1,-2,-3,-4,-5,-6,-7,-8,-9/),...

Why size of an empty array is 0 but size of an empty class is not 0?


c++,gcc,g++
For example: int main() { struct {} foo; int bar[0]; struct { int dummy[0]; } baz; cout << sizeof(foo) << endl; //display '1' cout << sizeof(bar) << endl; //display '0' cout << sizeof(baz) << endl; //display '0' return 0; } Please tell me is there any reason stand behind that...

scanf issue when reading double


c,gcc,double,user-input,scanf
I'm using MinGW on windows 7 to compile C files. My problem is a strange behaviour with scanf() to read doubles from user input. My code: int main() { double radius = 0; double pi = 3.14159; scanf("%lf \n", &radius); // after the input, it continues waiting... radius = ((radius...

How to check the values of a struct from an image/binary file?


c,gcc,binaryfiles
Is there anyway i can look into the values of a structure after compilation? objdump -td gives the function definitions and only the address where the structure is stored. The problem is i am getting a wrong address for one of the threads/functions in a structure when i run a...

Does gcc search CPATH recursively?


gcc,include
On a Linux system, does gcc recursively search the path declared in CPATH environment variable, or do I need to specify every Includes sub-directory explicitly?

My While True loop is getting stuck in python


python,while-loop,raspberry-pi,infinite-loop,raspbian
Hello I have been working on an infinite While True loop for the main file in my python code. I am working on a Raspberry Pi and my goal is that whenever one of the GPIO Pins senses an input it will print out a string. However When I push...

Why doesn't “Set-Item” work on Windows 7 PowerShell?


windows,powershell,raspberry-pi
I am trying to install Windows 10 IoT on my Raspberry Pi 2. The PowerShell documentation tells me to put in this: Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc> However, when I put it into my Windows 7 PowerShell, this comes out: At line:1 char:54 + Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc> + ~ The...

Raspberry Pi MicroSD Boot not working, MicroSD card unreadable on PC


raspberry-pi
I downloaded the necessary files for Raspberry Pi onto a MicroSD card, although the MicroSD card is no longer readable. When I put the card into the computer through a MicroSD to USB adapter nothing shows up in Windows Explorer. The card isn't present in Windows Disk Management either. How...

[ performance]— string::operator+= vs. vector push_back


c++,string,gcc,vector,char
I was testing the performance between these two operations, and on G++ 4.7.3, the string::operator+= version is about 2 times faster. My simple test: What can be the cause of such a big difference? g++ -O2 --std=c++11 #include <iostream> #include <ctime> #include <string> #include <vector> using namespace std; class Timer...

Why Unicode characters are not displayed properly in terminal with GCC?


c,gcc,unicode
I've written a small C program: #include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { wprintf(L"%s\n", setlocale(LC_ALL, "C.UTF-8")); wchar_t chr = L'┐'; wprintf(L"%c\n", chr); } Why doesn't this print the character ┐ ? Instead it prints gibberish. I've checked: tried compiling without setlocale, same result the terminal itself can print...

How -s option works actually in gcc compilers?


gcc,g++,command-line-interface
gcc & g++ provides command line option -s to reduce the size of executable file. But I want to know that how this -s option works exactly? What it does so that size of the executable reduces? How the size of file gets reduced?

Native Code: cannot use typeid with -fno-rtti


c++,osx,gcc,android-ndk,vtk
I'm trying to build native code on android because I want to use VTK for my android tablet. However, I am facing some issues when it comes to building one of the vtk examples. I know this problem has been covered here for an objective c issue but I guess...

__cplusplus < 201402L return true in gcc even when I specified -std=c++14


c++,gcc,g++,c++14,predefined-macro
The directive: #ifndef __cplusplus #error C++ is required #elif __cplusplus < 201402L #error C++14 is required #endif The command-line: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp My g++ version: g++ (tdm-1) 4.9.2 The error C++14 is required is generated even when I added -std=c++14, I don't know why. Please...

Scoping rules for struct variables in GCC


c,gcc,struct,clang,scoping
Consider the following C program #include <stdio.h> typedef struct s { int x; } s_t; int main() { int x; s_t a; scanf("%d", &x); if (x > 0) { s_t a; a.x = x; } printf("%d\n", a.x); } The a struct variable in the if branch clearly shadows the a...

fatal error: limits.h: No such file or directory


xcode,osx,gcc
On OSX, I can't compile simple programs from the command-line when I use an externally-provided compiler (e.g. gcc-4.8). System headers like limits.h cannot be found. Example error messages: fatal error: limits.h: No such file or directory Or: fatal error: stdio.h: No such file or directory and so on. What's wrong?...

Unclassifiable statement at (1) in Fortran


gcc,fortran,fortran90,gfortran
I am pretty new to to fortran and I don't really know why am I getting this error. integrand(i)=inte(x(i),beta,r2,r1) 1 Error: Unclassifiable statement at (1) calka11.f95:97.6: I have made all the variables into a module file and then call them using use and when I am getting those variables into...

Dereferencing pointer to incomplete type error for struct member access in Python swig C wrapper


python,c,gcc,compiler-errors,swig
What is the error while compiling swig Python wrapper under GCC 4.8.2? wfdb_python_wrap.c:3967:11: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); ^ wfdb_python_wrap.c:3967:36: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); source code from wfdb_python_wrap.c: ... #include <wfdb/wfdb.h> ... #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_WFDB_Siginfo_fname_set(PyObject...

How can I convert an int to a string in C++11 without using to_string or stoi?


c++,string,c++11,gcc
I know it sounds stupid, but I'm using MinGW32 on Windows7, and "to_string was not declared in this scope." It's an actual GCC Bug, and I've followed these instructions and they did not work. So, how can I convert an int to a string in C++11 without using to_string or...

Raspbian log files


raspberry-pi,raspbian
Where can I find all boot, driver or kernel related logs on a Raspbian? Could you please reply with a list as follows: Driver logs - /something/somethingelse.log Thanks!...

How is shellcode generated from C? - With code example


python,c,gcc,assembly,shellcode
I started taking an online course regarding software security. In one of the sections, I was instructed to execute a hidden C function using a buffer overflow. I got to thinking: what would happen if I could pass machine instruction directly to a stack unsafe executable? What I have been...

Django MySQLClient pip compile failure on Linux


python,linux,django,gcc,pip
Django documentation as of v1.8 recommends using mysqlclient connector for the framework. I'm attempting to pip install the package on Ubuntu 14.04 with Python 3.4 and running into a GCC error that I'm unable to find reference to. I'm not an expert on compiling software, so was hoping somebody can...

GCC on Solaris - parse error before `0x00000002'


c++,gcc,solaris
I'm working on a C++ project that is compiled on a few platforms, including Windows, Linux, and Solaris. The Solaris version of the code is quite old. I'm updating it with changes made over several years, and getting weird compiler errors with code that compiles fine on Windows and Linux....

Can I have optimization on, but not suffer from reordered statements?


c,gcc
My debug CFLAGS were always -g -O0. The latter mainly to disable jumps to unexpected line while debugging. Nowadays more and more programs refuse to compile with -O0, besides, -D_FORTIFY_SOURCE require optimizer. is it possible to compile with -O, but have predictable behavior in debugger? ...

Tell C++ that pointer data is 16 byte aligned


c++,gcc,sse,memory-alignment
I wrote some code with static arrays and it vectorizes just fine. float data[1024] __attribute__((aligned(16))); I would like to make the arrays dynamically allocated. I tried doing something like this: float *data = (float*) aligned_alloc(16, size*sizeof(float)); But the compiler (GCC 4.9.2), no longer can vectorize the code. I assume this...

How to check which symbols on my shared library have non-position independent code (PIC)?


linux,gcc,debian,powerpc
I'm trying to build a .deb package with debuild -i -us -uc -b and in the end I see: Now running lintian... warning: the authors of lintian do not recommend running it with root privileges! W: libluajit-5.1-2: hardening-no-relro usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 E: libluajit-5.1-2: shlib-with-non-pic-code usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 W: luajit: hardening-no-relro usr/bin/luajit-2.1.0-alpha W: luajit: binary-without-manpage...

gcc auto dependency full path


c++,gcc,makefile,g++
I have a simple project - it has a foo.cxx and a bar.h: // bar.h // nothing // foo.cxx #include "bar.h" // nothing else If I include bar.h with ""s, then the dependency file has everything with its full paths: $ g++ -std=c++11 -MP -MMD -MF /home/barry/sandbox/foo.d -c /home/barry/sandbox/foo.cxx -o...

(solaris) ld: fatal: … version 'GCC_4.2.0' does not exist


c++,gcc,linker
I'm trying to compile a c++ program for the first time on this machine (which is not mine), so I've written a simple hello world. My command to compile gets an error, >g++ testing.cpp -L/usr/local/lib ld: fatal: file /usr/local/lib/libgcc_s.so: version 'GCC_4.2.0' does not exist: required by file /usr/local/lib/libstdc++.so but I...

Access GPIO (/sys/class/gpio) as non-root


bash,raspberry-pi,chmod,chown,raspberry-pi2
The /sys/class/gpio can only be access as root by default. So I like that a new group gpio can use the files and dirs under /sys/class/gpio. To achieve that I added the following lines to /etc/rc.local (I'm on Debian): sudo chown root:gpio /sys/class/gpio/unexport /sys/class/gpio/export sudo chmod 220 /sys/class/gpio/unexport /sys/class/gpio/export So...

Range of immediate values in ARMv8 A64 assembly


gcc,assembly,arm64
My understanding is that immediate parameters in ARMv8 A64 assembly can be 12 bits long. If that is the case, why does this line of assembly code: AND X12, X10, 0xFEF Produce this error (when compiled with gcc) Error: immediate out of range at operand 3 -- `AND X12, X10,...

C++ chrono library on Raspberry Pi


c++,raspberry-pi,c++14,chrono
On a Raspberry Pi 2, I need to call a php file on a regular basis, typically every 100ms. I found this c++ code which looks like it does what I need and a test version of it compiles and runs fine using CodeBlock on Windows. I've updated the wheezy...

Ambiguous reference to variable


gcc,fortran,fortran90,gfortran,intel-fortran
So I am doing 2 modules which are linking to the main program. The first one has all the variables defined in it and the second one is with the functions. Module1: module zmienne implicit none integer, parameter :: ngauss = 8 integer, parameter :: out_unit=1000 integer, parameter :: out_unit1=1001...

Can I use STDIN for IPC?


c,gcc,ipc,stdin
Can I use standard input for interprocess communication? I wrote the following gnu c code as an experiment, but the program hangs waiting for input after printing the character defined as val. Neither a newline nor fflush in the sending process seem to alleviate the problem. #include <unistd.h> #include <stdio.h>...

How to override C compiler aligning word-sized variable in struct to word boundary


c,gcc,struct,bit-packing
I have a structure specified as following Member 1, 16 bits Member 2, 32 bits Member 3, 32 bits which I shall be reading from a file. I want to read straight from the file into the struct. The problem is that the C compiler will align the variables m1,...

minigw-w64 is incapable of 32 byte stack alignment, easy work around or switch compilers?


c++,windows,gcc,alignment,sse
I'm trying to work with AVX instructions and windows 64bit. I'm comfortable with g++ compiler so I've been using that, however, there is a big bug described reported here and very rough solutions were presented here. Basically, m256 variable can't be aligned on the stack to work properly with avx...

gcc compilation with linker - differences


c,gcc,linker
This will compile main.c and link created .o file statically with with abc library and dynamically with xyz gcc main.c -Wl,-Bstatic -labc -Wl,-Bdynamic -lxyz -o main But I am not sure about some other combinations: This will compile main.c to main - but what -lm will do in this case?...

gcc make dependency and object simultaneously


gcc,makefile,g++
I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently. This works: $ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o $ [ -s foo.d ] && [ -s foo.o ] && echo yay yay However, instead of generating foo.d,...

Java read bytes from Socket on Linux


linux,windows,sockets,network-programming,raspberry-pi
I'm trying to send a file from my Windows machine to my Raspberry-Pi 2, and I have a client and a server. The client should be able to send a zip file over the network to my server on my linux machine. I know my client and server work on...

Print addresses of all local variables in C


debugging,pointers,gcc,gdb,memory-address
I want to print the addresses of all the local and global variables which are being used in a function, at different points of execution of a program and store them in a file. I am trying to use gdb for this same. The "info local" command prints the values...

MinGW's ld cannot perform PE operations on non PE output file


gcc,assembly,mingw,nasm,osdev
I know there are some other similar questions about this out there, be it StackOverflow or not. I've researched a lot for this, and still didn't find a single solution. I'm doing an operative system as a side project. I've been doing all in Assembly, but now I wanna join...

GCC emits vastly different code using “-march=native” on similar architectures


c,gcc,assembly,sse,avx
I'm working on writing an OpenCL benchmark in C. Currently, it measures the fused multiply-accumulate performance of both a CL device, and the system's processor using C code. The results are then cross checked for accuracy. I wrote the native code to take advantage of GCC's auto vectorizer, and it...

Constructing priority_queue instance with Compare instance of different type


c++,gcc,constructor,containers
Could anybody please explain why my compiler (GCC) accepts the code below as valid? priority_queue<int, deque<int>, less<int>> pq(greater<int>()); I expect this constructor (for an instance of type having less<int> as Comparator, as specified for priority_queue instance pq) to be incompatible with an instance of greater<int> (passed as constructor parameter), which...

Makefile with two targets and two languages


c++,c,gcc,makefile
I work with C and C++ and thanks to this answer I was able to compile and run my project. Now I am writing a makefile to spare time. But things are getting complicated : Project structure project makefile client bin src c cc java server ... # Directories #...

Why it is allowed to initialize static variable with non const here?


c,gcc,initialization,const,static-variables
I was reading this. The first answer by @Andrei T says that A "large" object is never a constant expression in C, even if the object is declared as const. Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects...

ARM assembly cannot use immediate values and ADDS/ADCS together


gcc,assembly,arm,instructions
I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program: @.syntax unified .cpu cortex-m0 .text .global test .code 16 test: mov r0, #0 adds r0, r0, #1 bx lr When I try...

Popen.kill() failing


python,raspberry-pi
Update 2: So I piped the output of stderr and it looks like when I include shell=True, i just get the help file for omx player (it lists all the command line switches and such). Is it possible that shell=True might not play nicely with omxplayer? Update: I came across...

c++ segfault on one platform (MacOSX) but not another (linux)


c++,linux,osx,gcc,llvm
I'm getting a segfault on MacOSX ("Segmentation fault: 11", in gdb "Program received signal SIGSEGV, Segmentation fault"), appearing in the destructor in which a container is looped over with an iterator and memory deleted. I've tried with clang++, g++ (both part of LLVM) and homebrew g++. The segfault appears when...

How to have gcc warn about conversions from uint32_t to uint64_t?


c++,gcc,compiler-warnings
Let's take the following simple example: #include <vector> #include <cstdint> using ::std::vector; using ::std::uint64_t; using ::std::uint32_t; int main(int argc, char *argv[]) { vector<uint64_t> v; uint32_t i = 1; v.push_back(i); return 0; } When I compile it with: g++ -std=c++11 -Wall -Wconversion -Wpedantic a.cpp I don't get any conversion error. However,...

Make c++ macro2 containt quoted body of macro1


c++,gcc,c-preprocessor,qmake
I'm trying to make some kind of a simple system that calculates the number of builds, including this info in .rc file (for windows) and met the problem. Here it is: #define QUOTE(s) #s #define A 0,0,0,1 #define A_STR QUOTE(A) Expanding of A_STR: "A" but not "0,0,0,1" as I expected....

C++ GCC/MinGW Paths: ssp, ext, tr1; parallel, ext, bits, experimental


c++,gcc,clang,mingw-w64,libc++
Question: In the GCC/MinGW folder tree, there are duplicates of some header file names, in folders: ssp, ext, tr1; parallel, ext, bits, and experiemental ... Should explicit "include" directives for these folders be avoided in production code--as a best practice? OR, is there documentation online, regarding the legitimate scenarios these...