Is it possible to compile a file (dynamic library) that can run on all operating systems (Windows / Linux / MacOS)? If so, how?

  • No you can not. If it were so simple, all applications would have been cross-platform long ago. - AivanF.
  • In theory, mingw32 / 64 can be compiled for Windows on Linux. - maint
  • @AivanF. You can, at least one anti-virus engine is an MZPE file and works both in Windows and in Linux. - Vladimir Martyanov

2 answers 2

Compile the library as a single file that will work everywhere, will not work. The fact is that each operating system has its own format of executable files and library files (read docks for keywords - MZ, PE, ELF, a.out)

On the other hand, there are systems that allow running "non-native" programs. One of them is wine. It is included in almost any Linux distribution and allows you to run windows-based applications. True, this is not an absolute solution to the problem.

  • Additionally, I will say such a thing. Build an executable file under Windows, for example, on Linux is possible. This is called "cross-compiling": i.e. target platform is different from the platform where the code is going. But this never means that the collected code will run on the platform where it was going to ... - gecube

Can. If your program will not have any external dependencies and you will manually load it into a non-native OS and transfer control to it.