Are statically linked binaries built with gcc on Windows Linux Subsystem portable to all Windows systems? - windows-subsystem-for-linux

I have Windows 10 with the Ubuntu userspace based on Windows Linux Subsystem, with the gcc package installed. Using gcc -static, I built a statically linked binary, hello, that the usual utilities describe as follows:
$ ldd hello
not a dynamic executable
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=xxx, not stripped
If I take this executable to a random Windows system that doesn't have the Linux-supporting subsystem installed, will it still run?

No. It requires WSL to map Linux Kernel calls to Windows. Second it needs bash to load it since it's an ELF executable not a Windows one.

Related

How can I cross-build CMake for a 32-bit Linux distribution?

I want to run a new version of CMake on a 32-bit Linux distribution; but - I need to build it from source, since Kitware no longer provides 32-bit builds (of recent versions). I have access both to 64-bit Linux distros and to the target machine.
What do I need to do in order to perform and deploy the cross-build?

What is the way to run c program's .exe file compiled on Windows OS to IMX8M Yocto Linux Board

I want to run hello.exe file generated on Windows OS platfrom for simpe hello.c file on IMX8M yocto linux board. I am very new to use this board and I am not finding any helping material on the same. Can anyone guide me is it possible or not and where can I find related documents.
If it's not possible, what are the other ways to run .exe generated from any HOST OS to Yocto Linux board.
I think there is some misunderstanding.
As the host and the device are not the same architecture (x64/ARM) and the same OS (Windows/Linux), you need to cross-compile your code. This is done by using a specific compiler, able to run on your host machine, to generate your binary for your device machine.
If you want to compile an application for your iMX8M from your Windows computer, you will need to find a cross-compiler toolchain able to run on Windows, generating binaries for Linux ARM architecture.
If you use Yocto, you can generate a SDK, which contains a cross-compiler toolchain by using bitbake <image> -c populate_sdk or bitbake <image> -c do_populate_sdk (depending on your Yocto version).
By default Yocto generates a SDK for a Linux host, so you will need to develop on a Linux OS.
There is aslo a specific meta that helps to generate a SDK for Windows: meta-mingw

Linux or Windows version of a library in Cygwin?

I have developed some codes in Linux which use boost::serialization library. Now I want to copy my files into Cygwin and compile them to produce executable for Windows. I know that I should use Mingw-64 g++ compiler. But how about boost library? Should I download the Windows version or the Linux version of this library?
In Cygwin, you install Boost libraries as per Unix/Linux. From the documentation
Getting Started on Windows
A note to Cygwin and MinGW users
If you plan to use your tools from the Windows command prompt, you're in the right place.
If you plan to build from the Cygwin bash shell, you're actually running on a POSIX
platform and should follow the instructions for getting started on Unix variants.
Other command shells, such as MinGW's MSYS, are not supported—they may or may not work.

How to decide library install path on different linux systems?

Fedora have dynamic libs on /usr/lib64 and /usr/lib, for 64-bit and 32-bit libs separately; while 64-bit Debian install some 64-bit libraries on /usr/lib/x86_64-linux-gnu, but seems some 64-bit libs are still in /usr/lib.
This looks pretty messy. So when I write a cmake file for my project, how to decide the place for installing the compiled libs?
use GNUInstallDirs, it will do everything for you.

Ubuntu-compiled program to run on Unix webserver

I have compiled an Ada program on Ubuntu using GNAT.
Afterwards, I tried a few test runs with that program and it worked properly.
But when I uploaded this to my Apache (UNIX) webserver and tried to run the program, there was no output. Why is this so?
Could it be that programs which have been compiled on Ubuntu don't work on a UNIX server?
(Sorry for the stupid question!)
Linux version of the system I use for compiling (uname -a):
Linux ubuntu 3.0.0-12-generic #20-Ubuntu x86-64 GNU/Linux
Linux version of the system I want to run the program on later (uname -a):
Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux
For compiling on the Ubuntu machine, I use:
gnatmake -O3 myprogram -bargs -static
When you build a GNAT program (gnatmake my_program), by default it links against dynamic libraries (libgnat.so, libgnarl.so). These libraries are part of the GNAT system and are very unlikely to be available on your web server.
If you say ldd my_program it will show you the shared libraries used.
You can force the build to use the static GNAT libraries by saying
gnatmake my_program -bargs -static
(the -bargs -static must come after regular flags like -O2).
Edit: more info on -bargs and friends.
You must make sure that the server has the libraries your app links against or link them statically like already suggested by others. Some other comments point out that you need to "cross compile" or that the server won't run 64 bit binaries. This is easily solved unless the app you're building is very complex.
gnatmake --GCC='gcc -m32'
Will make a binary that will run on a 32bit system. However the chief problem is that the servers (g)libc is very likely to be older than what's on your ubunu box. Programs compiled against newer glibc will not necessarily run on systems with an older glibc installed.
for more info and plenty more links, look here:
Linking against an old version of libc to provide greater application coverage
How can I link to a specific glibc version?
edit:
Besides, apache may not be configured to accept invocation of external binaries. Have you "tried to run the program" with something you know exists on the server? Try to run something trivial like /bin/ls to make sure your method of running the program works. Look at the logs if it doesn't work. Programs need to be executable, by the way: chmod 755 /path/to/webeserver/uploads/ada-app
Why don't you just compile it on your Webserver instead of your local machine ?
Aswell cat /etc/issue or cat /etc/release could give us some information about the distribution you're using.