Compiling a Linux program for ARM architecture - running on a host OS - linux

I have a ARM Coretex-A8 development board from Freescale (i.MX53) running Linux Ubuntu. It boots up just fine and I can access the system with mouse/keyboard/terminal.
To get started I would like to make an application running on the board inside the host OS, just as you do when you run application on your PC.
My problem is to compile my test program, using toolchains like YAGARTO which is based on gcc i end up in trouble with the linking bacause I have not defined any startup script.
I find lot of information on building "bare metal" configurations (inluding compiling the kernel and make load and link scripts), but not anything usefull for making a application running on a host OS.
My development environment is running on Windows 7. I also have the option to run on Linux X86, but i doubt this whould help me making ARM applications.

For ARM-Linux application development the preferable choice is a Linux Host(x86) machine with a ARM toolchain installed in it. In Ubuntu Desktop machine you can use the following command to install ARM toolchain:
apt-get install gcc-arm-linux-gnueabi
After toolchain installation you can use the following command for cross compilation:
gcc-arm-linux-gnueabi-gcc -o hello hello.c
Using this toolchain you can cross-compile your C program using Standard C library without the need of startup code. Applications can be cross-compiled at your Host Linux(x86) platform and run on Target Linux(ARM) platform.
Windows version of ARM-Linux Toolchain is also available. You can get it from here.
Linaro Developers Wiki - an open organization focused on improving Linux on ARM, will be a good reference for your work.

Related

Cross-compiling in Linux Alpine targeting Ubuntu

I have a virtual machine running Alpine Linux with gcc 8.2.0, and I would like to use it as a sandbox to compile programs to be installed on an Ubuntu machine. What is the procedure for doing so? I guess I will need to perform cross-compilation, but haven't found anything about it.
You can create an Ubuntu chroot with debootstrap, and compile your sources in the chroot. I doubt there is an easy way to cross-build directly from Alpine Linux.
It is also not clear why you would want to do this. If you have packaged your sources for Debian/Ubuntu, you should use a VM for that operating system and one of the native build tools (such as pbuilder or sbuild) to build in clean build environments.

How to Build GCC For Windows on Linux?

I have a VM running CentOs Linux on my Windows 10 machine. Yesterday I built the GCC from source, and saw an option where you could build it to cross compile. My question is this: is it possible (and if it is, how is it done), to compile GCC so that it is capable of building Windows executables on Linux (that I can then run on my computer)? I would like to avoid using MinGW if at all possible so that I won't have to use the special libraries.

Building with Mono mkbundle on x86 won't run on x64

I have a .NET application that runs on Linux, using Mono. I want to avoid users having to install Mono, so am using mkbundle. I am running mkbundle on an x86 machine, with the expectation of the resulting binary being able to run on x64 machines:
mkbundle MyApp.exe *.dll -o MyApp
I can then run the resulting application on the build machine with `./MyApp'
However, when I copy it to an x64 machine (and make it executable) it won't run, just outputting:
bash: ./MyApp: No such file or directory
If I try ldd I get:
not a dynamic executable
Shouldn't binaries built for x86 run on x64 systems?
I'm rather new to Linux, and it seems x86/x64 isn't quite as straightforward as it is on Windows, as many x64 Linux distributions don't ship with the capability to run 32-bit binaries.
After installing 32-bit libraries on the x64 machine, the x86 code will execute as expected (e.g. on Ubuntu 7.04, apt-get install ia32-libs.
While this works, as I need to target a number of distributions I've decided to just create separate builds for x86 and x64 instead.

Cross-platform build under Windows targeting Linux using CMake

I am developing a software in C++ on windows 32-bit (using MSVC++), but since I want to be able to use my software on every platform, I have decided to use CMake as my build generator.
Therefore, I am still just a beginner in CMake. From the CMake tutorials, I understand that in order to cross compile codes, first a toolchain simulating the target platform should be installed on the host platform. Then using the appropriate target-platform C and C++ compilers provided by this toolchain, CMake would be able to generate makefiles etc.
Now, I want to build my code for Linux platform(GNU/Linux) on a Win32 platform. I tried doing the above procedure using CMake combined with Cygwin and using gcc and g++ as compilers. It built fine, created makefiles, and when I issued "make" in Cygwin terminal, the generated makefiles were "made". Now I have got an executable which I was hoping would run on Linux platform. But on Linux I get the error: bash cannot execute binary file.
Using command file executablename, I realized the executable which is made by the above procedure is of type PE32 which is only for Windows.
Now my question is: Is my understanding of cross-platform build procedure using cmake correct?Or should I just use another Linux toolchain under windows to get a Linux ELF executable? What toolchains come to your mind which would give me what I want?
Many thanks
Setareh
You will want to look here: cmake-toolchains(7) if you do cross compiling. However, I would suggest that you install a Linux VM like virtual box on your windows machine and build naively on Linux. It will compile much faster and you will not have to worry about cross compiling. You can mount the windows disk from the linux VM so you can share the same source tree. The linux VM will compile much faster than gcc running under windows.
Your understanding of CMake is correct... it will determine how to create the build system you request (or is default for the platform you are currently on) based on rules in your CMakeLists.txt file. However, this won't necessarily help you compile for linux on a windows machine if you don't have something installed that can target linux.
To compile targeting linux, you will need to use a linux compiler. The link posted by #stjin tells you how to install one on cygwin. Then, to set up your CMake build, do this in the terminal:
CC=gcc-linux CXX=g++-linux cmake . [options]
This will tell CMake to locate the special linux targeted compilers. Hopefuly, after compiling with these compilers you will be able to run on linux.

How do I use cygwin to cross compile to linux, when I have an application that needs libX11.so, libGL.so, and libGLU.so?

Will I have to use the crosstool that cygwin provides to make the libX11.so, libGL.so, and libGLU.so libraries using their respective source code? Or do you know where I can find them compiled already for crosstool (I'm new to this cross compilation)?
Just for clarification: I'm on a windows 7 machine trying to get my application also to compile for linux systems by using cygwin's cross compilation. The application uses OpenGL. Thanks
To cross-compile for Linux you should install the needed development libs and headers on a linux box[1] and then copy /usr/lib and /usr/include your cygwin environment (e.g. /crosscompiler/linux/...). When you build the cross compiler in cygwin, tell it where those native linux headers and libs are so they'll be used when you compile your app.
[1] If you're looking to run on a wide variety of linux boxes make sure you pick an older linux distro (e.g. Red Hat 9) to ensure your app doesn't have dependencies on very new glibc, etc..
Why do you want to use Cygwin?
There is instructions on the OpenGL Wiki about how to use OpenGL on Windows using MinGW.
MinGW use the same GNU tools that are available on Linux (GCC, GDB, GMAKE, etc.) but produce Windows native executables. So, you shouldn't have trouble compiling your source code on both platforms.
I just ended up building on a native Linux machine.

Resources