Cross Compile a automake project? - c++

I am developing an application for enocean. I am able to compile it for my Host system. I want to cross compile it for beaglebone black running openwrt. I have cross compiler and all other libraries. I am not sure how to change the existing configure, Makefiles to cross-compile it.
Please help!

you don't have to change anything. autotools comes with full cross-compilation support.
Just pass the proper --host= flag for your target architecture, e.g.:
./configure --host arm-linux-gnueabihf
This will look for toolchain programs with the given prefix (in the above case, it would look e.g. for a compiler arm-linux-gnueabihf-gcc) in your current $PATH. Most cross-compiling toolchains should automatically adhere to this convention.
See also the official documentation

Related

How can i use neovim and coc.nvim for develop windows c++ apps on linux

I develop c++ apps on linux and i use neovim with coc.nvim and coc-clangd plugins.
I want to develop an app for windows but i comfort with linux and neovim so i want to use them for it. But i get some include errors with some windows headers (etc. "windows.h").
I use linux only for writing the code and i'll compile the program on windows. How can i prevent this errors and use windows headers with coc.nvim?
i'll compile the program on windows
You can cross-compile it from Linux. It's only marginally more difficult than getting the code completion to work.
Get the standard library headers (and libraries, if you want to cross-compile) from MinGW.
Your package manager might have those, or you can get them from https://winlibs.com/.
I prefer getting those from MSYS2, and made scripts to automate this (since MSYS2 is otherwise Windows-only):
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc
Figure out the Clang flags needed to cross-compile.
Unlike GCC, which for every target platform requires a separate compiler distribution, Clang is inherently a cross-compiler. You only need a single Clang distribution to compile for any supported platform.
Download Clang from your package manager, and point it to the freshly downloaded headers and libraries.
Following flags work for me: clang++-14 1.cpp --target=x86_64-w64-mingw32 --sysroot=/path/to/quasi-msys2/root/mingw64 -fuse-ld=lld-14 -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc.
--target and --sysroot are crucial. The latter needs to point to the files you've downloaded. The remaining flags are less important.
Running this should produce a.exe, runnable with wine a.exe.
Feed the same flags to Clangd.
There are several ways to set compiler flags for Clangd.
The easiest one is to create a file named compile_flags.txt in your project directory, and put the flags into it, one per line:
--target=x86_64-w64-mingw32
--sysroot=/path/to/quasi-msys2/root/mingw64
-fuse-ld=lld-14
-pthread
-stdlib=libstdc++
-femulated-tls
-rtlib=libgcc
Then Clangd should do the right thing for any source files in this directory.
Apparently, my Quasi-MSYS2 can somewhat automate this.
After running the commands above (make install _gcc and others), run make env/shell.sh, and run your editor from this shell.
Replace compiler_flags.txt with compiler_commands.json with following contents:
[
{
"directory": "/your/sources",
"file": "/your/sources/1.cpp",
"command": "win-clang++ 1.cpp"
}
]
Where win-clang++ is a Clang wrapper I ship, which automatically adds the flags I listed above.
Configure your editor to add following flag to Clangd: --query-driver=/path/to/win-clang++ (use which win-clang++ from quasi-msys2 shell to get the full path).
This makes Clangd obtain the right flags automatically from this wrapper.
You can't use windows.h while you're compiling a Linux native application. If want to make your application platform ready and you're using some kind of OS native cals, then you have to probably use defines like #if _WIN32/__linux__ and so on. At the end, you can cross-compile your application to Windows while you're running on Linux as well.

How to create CMake cross-compiling toolchain for VxWorks?

I want to generate vxworks 6.x makefiles and workspace via CMake, and there is no support for VxWroks in CMake. How do I create a relevant generator for my platform anf the correct toolchain?
I'm new to CMake. I managed to create some test project that generate for windows VS 2015 and Ubuntu.
I tried to create one for VxWorks 6.x with GNU and DIAB compiler, but there is no support for it in CMake.
I read about something called toolchain, cross-compiling and platform files (.cmake) but I don't understand how to write it and where to put it.
I saw many examples in the internet but didn't understand if I need to rebuild the CMake with the new platform files or just reference to them form the toolchain or from CMakeLists.
I'm using the gui version of CMake 3.14.
I setting the generator as: Eclipse CDT4 - Unix Makefiles.
When I choosing the option of cross-compiling and provide name VxWorks, version, c++ compiler (gnu/4.1.2-vxworks-6.6/x86-win32/bin/c++ppc.exe), it write that the compiler is unknown and that I need to create Platform/VxWroks. It cannot build a simple test program.
I saw some post of someone who succeeded to create all required files :
Do (Cross-compile) platform files require an include guard?
But I couldn't download some examples to test it and a tutorial of how to do it.
I would like to be able to cgreate a generator with CMake for VxWorks 6.x to cimpile libraries and exacutable (.vxe) but don't know what to do.
CMake is not well supported in VxWorks 6, but CMake is supported from the Workbench/Eclipse GUI environment in VxWorks 7. Neither version supports command line cmake, e.g. "cmake ."

Cross-compile Qt for specific arm target from 64bits Linux

I'm currently trying to compile a project and port it to a 32bit target deploying a Linux based system.
My host machine runs x86_64 Debian Stretch and my target is an Atmel SAMA5d2 running a custom Linux.
My cross toolchain is generated from buildroot.
At the moment I'm able to cross compile applications for the target using the buildroot generated toolchain. However, I would like to integrate Qt and build Qt apps for the target.
To be able to build my applications for the targetted platform I need to compile Qt for my target.
To do so I have to tell Qt to use the buildroot toolchain instead of the native one.
From what I found I either have to provide -device <device> --device-option CROSS_COMPILE=$TOOLCHAIN_PATH or -xplatform <mkspec> to configure Qt with the expected toolchain.
Obviously my target is not in the device list under qtbase/mkspecs/devices so I think the best solution is to create a mkspec for my target.
My command should look like this :
./configure -xplatform <my_mkspec> -embedded arm -prefix <customQtPath>
However I'm kinda lost and I don't know how to do it only from documentation and what I found by googling my problem.
Also do I need to specify the target is 32bit as armv7 is only 32bits?
I would be glad to have some help on this.
Thanks.
Your assumptions are correct. You can read similar specs and create your own, those are pretty simple. For instance Pi2 is an armv7 device, you can start from this qmake.conf. Then, pass to configure:
-device <given_name> -device-option CROSS_COMPILE=<path_and_prefix> -sysroot <your_sysroot>
just change paths, tune cflags if needed etc... Then follow build tutorials.

How to determine architecture to build GCC cross compiler?

I'm trying to set up a build server on Linux which I will use to build C/C++ apps for Windows and Mac.
I know that GCC supports a body of different architectures but I can't figure out how to determine targets against which I need to build GCC cross compiler.
Could someone please explain this to me?
Thanks in advance.
P.S.
I know that precompiled solutions already exist, but I just want to understand this in detail by making a deep dive.
On the target machine, run:
gcc -dumpmachine
Then use the result in the --target option when building your cross toolchain.

How to cross-compile Boost libraries

I'm trying to cross-compile the Boost library for an ARM platform (poky toolchain) and I'm new to cross compilation. I'm having issues at the first step -- running bootstrap.sh. I see many posts regarding boost cross-compilation, but not so many helping at the bootstrap level.
A few questions:
1) What should I put exactly in 'user-config.jam'? I tried:
using gcc : arm : arm-poky-linux-gnueabi-g++ ;
I see many ones specifying an exact path to the compiler.
2) Where's the best place to put the user-config.jam file? I tried my home (~) folder and the current folder.
3) The toolchain has a file named "environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi", should I "source it" before running bootstrap?
Any help appreciated, thanks.
Common tasks - 1.64.0
https://www.boost.org/doc/libs/1_64_0/doc/html/bbv2/tasks.html
Cross-compilation
Boost.Build supports cross compilation with the gcc and msvc toolsets.
When using gcc, you first need to specify your cross compiler in user-config.jam (see the section called “Configuration”), for example:
using gcc : arm : arm-none-linux-gnueabi-g++ ;
After that, if the host and target os are the same, for example Linux, you can just request that this compiler version be used:
b2 toolset=gcc-arm
If you want to target a different operating system from the host, you need to additionally specify the value for the target-os feature, for example:
# On windows box
b2 toolset=gcc-arm target-os=linux
# On Linux box
b2 toolset=gcc-mingw target-os=windows
For the complete list of allowed opeating system names, please see the documentation for target-os feature.
When using the msvc compiler, it's only possible to cross-compile to a 64-bit system on a 32-bit host. Please see the section called “64-bit support” for details.