Compiling code on Jetson TK1 - c++

I am compiling an application using the gcc arm cross compiler(arm-eabi-g++). I want to execute the code on the jetson tk1 target. When I copy the executable and run it on the target. I get an error saying -bash: ./Proj: No such file or directory
Should I include any extra conditions while building, inorder to run it on the target?
Can anyone suggest any other cross compiler that works?

It might be differing of system architecture and program architecture.
Look for the architecture of TX1 with command
uname -p
From JetPack v2.2 Jetson TX1 can be installed with aarch64 or armhf architecture
Simpliest way to cross compile is to use arm-linux-gnueabihf-g++ for armhf and aarch64-linux-gnu-g++ for aarch64. You can run armhf programs on aarch64 but you need to install armhf versions of all necessary libraries like libc or libstdc++:
sudo apt-get install libc6-dev:armhf

Related

How to cross compile linux arm to x86

I'm using an m1 pro macbook pro.
Up until now, I used intel macbook.
My program is written in c/c++ and the target is ubuntu x86_64.
I tried running ubuntu x86 docker (qemu) and it's super slow - to the point it's unusable.
I have linux ubuntu (arm) installed using parallels and would like to compile for x86 target instead of arm.
How do I do it?
On Ubuntu, I would suggest an apt install gcc-x86-64-linux-gnu g++-x86-64-linux-gnu, and then invoking the installed compiler with the x86-64-linux-gnu prefix (for gcc, x86-64-linux-gnu-gcc) to create x86_64 binaries.
Do note that if you target x86_64 you won't be able to run the programs you build natively, but you should be able to package the binaries created for execution on an x86_64 machine.
Install docker-desktop on your mac and run this docker container with the command:
docker container run --platform=linux/amd64 -it -p 6080:6080 -e WIDTH=1920 -e HEIGHT=1080 yoas1/xubuntu-desktop:1.0
Don't forget to create volume to the code directory.
In your browser go to: http://localhost:6080/vnc.html to access the xubuntu desktop
Image on Dockerhub

Install arm64 packages on A amd64 machine

I have A Raspberry Pi 3 device, the arch is arm64. And I have a ubuntu computer, the arch is amd64. I am doing the cross compile. I want to do the cross compile my code on the ubuntu and then copy the executables to the Raspberry to execute. My software depends opencv, ffmpeg...etc. I Have tried the MultiArch solution. When I try to download ffmpeg:arm64, the apt show me this error.
So I tried to download the first dependency libavcodec58, but the result is:
and When I tried to install the dependency glibc, the result is here:
The Apt will remove all the libraries from my current system.
So could anyone can help me about this?

Compile Readline for x86 system (static mode)

I am writing a program in QT Creator, for the x86 architecture, using Debian 9 x86. The program will use GNU Readline library [8.0]. Also, my program must be statically built (QT is already statically built). For this I downloaded Readline from here.
Then performed the configuration for the static assembly:
./configure —prefix=/home/out/readlinelibs/ —enable-static —with-curses
then i performed the construction:
make
and installing libraries
make install
In QT's pro file I added the path to the libraries:
LIBS += -L/home/out/readlinelibs/lib -static -lreadline -ltinfo
When compiling the program I get the following error in QT:
error: cannot find -ltinfo
How to build readline in static mode? Thanks.
P.S.: in Debian x64 I also built readline and everything works well.
It was the lack of a tinfo library, as mbieren advised. I performed the installation on a 64-bit system as follows:
Added ability to install 32-bit packages:
sudo dpkg --add-architecture i386
I scanned the package and found that i need. You can do the scan so:
sudo apt-cache search tinfo
Finally i installed that i need:
sudo apt-get install lib32tinfo5 lib32tinfo-dev
Now the compilation of my program for 32-bit architecture is completed successfully!

How to get "g++ -mx32" to work on RHEL 7.2

I am new to x64_86, but forced to use it because RedHat dropped its 32-bit OS support in RHEL 7.x. I have to complile a lot of code, and am not ready to jump to x64 yet (because I do not need 64-bit addresses and do not want to face all related porting issues). So I have considered using -m32 and -mx32, and decided that -mx32 is the best route for me. However, while -m32 works fine on my build machine, when I use -mx32, I get this error:
In file included from /usr/include/features.h:399:0,
from /usr/include/string.h:25,
from zz.cpp:1:
/usr/include/gnu/stubs.h:13:28: fatal error: gnu/stubs-x32.h: No such file or directory
# include <gnu/stubs-x32.h>
^
compilation terminated.
I searched the web for solutions and some links indicate that I have to install some mysterious "multilib" rpms for g++ and gcc, however, I cannot find these anywhere. Others suggest that I have to install Linux in the x32 mode and build libgcc for x32, which sound extreme. Any ideas or leads? Did someone actually try g++ -mx32? Maybe it is not even supported on the RH platform... Thanks!
P.S. In order to get the "-m32" option to work I had to install:
yum install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686 ncurses-devel.i686
This one fails (yum cannot find these RPMs) - allegedly these are required for -mx32 to work:
yum install gcc-multilib g++-multilib
:(
Multilib is indeed your answer, but do not know why your repo does not support it. I installed mine via apt-get:
sudo apt-get install gcc-multilib
Although it uses 64-bit instructions, it uses the 32-bit ABI so annoyingly will not run under WSL (Windows Linux subsystem), which only supports the 64-bit one.

How to compile for Windows on Linux with gcc/g++?

I have written some effects in C++ (g++) using freeglut on Linux, and I compile them with
g++ -Wall -lglut part8.cpp -o part8
So I was wondering if it is possible to have g++ make static compiled Windows executables that contains everything needed?
I don't have Windows, so it would be really cool, if I could do that on Linux :)
mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32, for example.
Ubuntu, for example, has MinGW in its repositories:
$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]
Suggested method gave me error on Ubuntu 16.04: E: Unable to locate package mingw32
===========================================================================
To install this package on Ubuntu please use following:
sudo apt-get install mingw-w64
After install you can use it:
x86_64-w64-mingw32-g++
Please note!
For 64-bit use: x86_64-w64-mingw32-g++
For 32-bit use: i686-w64-mingw32-g++
One option of compiling for Windows in Linux is via mingw. I found a very helpful tutorial here.
To install mingw32 on Debian based systems, run the following command:
sudo apt-get install mingw32
To compile your code, you can use something like:
i586-mingw32msvc-g++ -o myApp.exe myApp.cpp
You'll sometimes want to test the new Windows application directly in Linux. You can use wine for that, although you should always keep in mind that wine could have bugs. This means that you might not be sure that a bug is in wine, your program, or both, so only use wine for general testing.
To install wine, run:
sudo apt-get install wine
Install a cross compiler, like mingw64 from your package manager.
Then compile in the following way: instead of simply calling gcc call i686-w64-mingw32-gcc for 32-bit Windows or x86_64-w64-mingw32-gcc" for 64-bit Windows. I would also use the --static option, as the target system may not have all the libraries.
If you want to compile other language, like Fortran, replace -gcc with -gfortran in the previous commands.
I've used mingw on Linux to make Windows executables in C, I suspect C++ would work as well.
I have a project, ELLCC, that packages clang and other things as a cross compiler tool chain. I use it to compile clang (C++), binutils, and GDB for Windows. Follow the download link at ellcc.org for pre-compiled binaries for several Linux hosts.
From: https://fedoraproject.org/wiki/MinGW/Tutorial
As of Fedora 17 it is possible to easily build (cross-compile) binaries for the win32 and win64 targets. This is realized using the mingw-w64 toolchain: http://mingw-w64.sf.net/. Using this toolchain allows you to build binaries for the following programming languages: C, C++, Objective-C, Objective-C++ and Fortran.
"Tips and tricks for using the Windows cross-compiler": https://fedoraproject.org/wiki/MinGW/Tips
For Fedora:
# Fedora 18 or greater
sudo dnf group install "MinGW cross-compiler"
# Or (not recommended, because of its deprecation)
sudo yum groupinstall -y "MinGW cross-compiler"