Build and run Android native application (executable) on Ubuntu - c++

I have code base written in C++. Build system uses Android's ndk-build script with makefiles defined for shared lib and executable. Binary runs on Android device.
My Question is: is there possibility to use current build configuration and build this executable to run on my local host e.g. Ubuntu?
I tried (with simple example as "hello world") with ABI change to x86_64 but this doesn't work. Executable file uses dynamic linker from Android' environment.
Do you have any idea how to setup this?

Not with the same build system. ndk-build can only build Android binaries.
If you migrate your build to another system (make, cmake, whatever) then your code might work. If the only pieces of the NDK you're using are libc/libm/libdl, then it should work (although there are a few Android extensions in libc and libdl). If you're relying on any of the Android framework libraries then it won't work because those don't exist on an Ubuntu system.

Related

conan packages vs mingwin conflicts how to fix?

I use conan as a dependency manager for a large C++ project. The project was built for Linux and I am porting it to Windows.
Due to this I am compiling with mingwin since that development environment is closer to mine.
However, conan knows it's running on windows and so it downloads windows binaries.
I am finding that although compilation works, linking fails because mingwin binaries and MSVC binaries are incompatible.
I am not sure if I need to try to instruct meson (my build system) to use cl as the compiler, or trick conan to download Linux libraries instead of windows.

How to build a Qt C++ application that doesn't need VC Redistributables on a pc to run

I am building an application using Qt C++ and I want it to run on windows computers without having to install VC Redistributables. Apparently when user tries to run the application an error pops that says that VCRUNTIME140.dll is missing.
Build both Qt and your application using compiler option /MT?
https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
I recommend using GCC (i.e. MinGW) as the compiler. If you do that, your app will generall depend on the msvcrt.dll that comes with Windows and doesn't need to be installed specially (but it depends on exactly how the GCC compiler is configured). It will also possibly depend on some GCC runtime library DLLs that you can just put in the same directory as your EXE.
MSYS2 is a good development environment for using MinGW on Windows: https://msys2.org
I also made a useful set of tools that is capable of cross-compiling statically-linked MinGW/Qt applications from Linux: https://github.com/DavidEGrayson/nixcrpkgs
The Qt applications I build with nixcrpkgs come out as single, standalone EXEs that do not need to be shipped with any DLLs.

Yocto package generation without modifying distributions on targets (ARM & x86)

Currently, I'm developing a C/C++ Application with the following characteristics:
Multiple target platforms - ARM (Raspbian) and manufacturer-modified x86 distribution
CMake is used to compile C/C++ application
Cross-compilation for ARM and the customized x86 distribution => with CMake (and toolchains to cover cross compilation)
Multiple dependencies (other github repositories) which are separately cross-compiled (according to github READMEs). These are referenced in the CMake of the project. The CMake decides if it uses the ARM or x86 libs.
For deploying I copy the cross-compiled dependency libs to /usr/lib on the target. Afterwards, the cross-compiled application can be launched on the target.
As cross-compilation is very annoying because it's full of pitfalls and I'll need many more dependencies in future, I decided to move to another build system to make things easier:
My goal is to get a rpm/deb file which can be easily installed on the target systems
After a few hours of research, I found out that via Yocto cross-compilation can be managed easier. In addition, it's possible to build deb/rpm/... files which can be installed on the targets.
Anyhow, as far as I understood, this deb/rpm/... file can be only installed on the yocto distribution/image which has been used for compiling => In other words, I would have to flash a completely new distribution on our targets (raspberry & x86). Unfortunately, this is no option for me (because of the custom x86 target).
Question 1: Is it correct that I have to replace the distributions on the targets in order to install the created packages?
Question 2: Is there a way how to create cross-compiled deb files which can be installed on existing distributions? If yes, what do I have to do to achieve this?
I assume that my current build strategy isn't the best. If you have any idea how to make it better, feel free to let me know.
Thanks,
Christoph

Publishing exe application

I have written a code in C and C++ that uses PCRE library. To test my code I use Cygwin which contains MinGW and it works fine when I run my code from console but I get the following error when I try to install the .exe file.
The program can't start because cygwin1.dll is missing from your computer
How can I publish .exe application that works on windows with all its dependancies?
As it depends on cygwin1.dll is NOT a mingw program it is a cygwin one.
If you want to built a mingw program you need
1) install a cygwin to minw cross compiler; two are available depending on your arch
mingw64-i686-gcc
mingw64-x86_64-gcc
2) install the needed additional libraries, depending on your arch and the pcre release you want to use:
mingw64-i686-pcre
mingw64-i686-pcre2
mingw64-x86_64-pcre
mingw64-x86_64-pcre2
3) set your build as cross one.

"Cannot execute binary file" when running compiled c++ programs with Eclipse on Ubuntu for Windows platform

I would like to move from Visual Studio on Windows platform to Eclipse on Ubuntu for c++ development, since I develop almost all my programs on Java, with Eclipse, and I just use a Windows virtual machine in order to develop C++ programs for Win OS. So if I would be happy being able to not use Windows VM at all. However, I've managed to configure MinGW and Eclipse successfully enough to compile programs, but not to execute them.
Steps I've gone through so far:
I've installed mingw32 package and dependencies:
$ sudo apt-get install mingw32
I've installed Eclipse Mars for C/C++ development (manually, to keep this installation isolated from other Eclipses I have) and created a new project in this way:
- New C++ project.
- [...]
- Cross-prefix: i586-mingw32msvc-
- Cross path: /usr/bin/
With this configuration I'm able to correctly build a .exe which I can successfully execute on Windows, but when trying to debug it or execute it under Eclipse I get this error: "cannot execute binary file".
Googleing I've seen some posts suggesting to use wine in order to execute the .exe, but I thought mingw32 would be able to execute it. Am I wrong and this is not possible or just doing something wrong?
Mingw32 is a windows compiler, and will compile source to a Windows executable file. Additionally, the compiler cannot execute files (as worded in the question), it just compiles the source code to an executable form, in this case the windows executable (*.exe). So yes, in order to run the .exe in Ubuntu you would need something like Wine which emulates a Windows environment
mingw is a set of GNU tools for building native Windows executables.
It does not execute anything.
If you really want to cross-compile for Windows, you need Windows or an emulator for the execution.
To build for Ubuntu you can just use the native compilers.
sudo apt-get install gcc