Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate executable file that can run on both Unix and Linux?

Tags:

c++

c

g++

I am using g++(under linux) to compile a piece of c code. The compiled executable file works good on linux. But it doesn`t run on unix(SunOS). How to make the compiled file runs on both Unix and Linux? Thank you.

like image 568
mozartsg Avatar asked Jan 01 '26 05:01

mozartsg


1 Answers

The POSIX.1 standard guarantees compatibility on source code niveau. This is—every program that is written to use the POSIX.1 APIs is guaranteed to compile and run on any POSIX platform. POSIX does not and did never guarantee that binaries are portable between different platforms, even if all of them are compliant.

Do not assume that you can execute the same binary on different platforms. While there are some toolkits that provide varying levels of emulation, this doesn't alway work.

For the special case of executing Linux binaries, there are some solutions, like lxrun for Solaris or the builtin system-call translation-layer the maps Linux to FreeBSD system calls on FreeBSD.

like image 78
fuz Avatar answered Jan 02 '26 18:01

fuz