C ++ Portability between Windows and Linux

I have a question on how to write transfer programs between windows and linux.

I recently realized that if you are writing a program that uses any external library, if this library does not have a Linux version (or a Windows version when developing on Linux), then you are screwed.

Then my question is: if I write a program in linux that references lol.a, and then I want to compile and run it on windows without recompiling lol.a to lol.lib, maybe something like MinGW or Cygwin do it? Link to .a files on a Windows platform to output a .exe file that Windows can run?

+4
source share
4 answers

You will have to recompile all libraries for different operating systems. Binary formats for libraries range from operating system to operating system. More importantly, even if you are not using libraries, you need to recompile them for the simple reason that different operating systems have different calling conventions. The only way around this is with the virtualizer.

In particular, CygWin cannot run Linux programs. at all. CygWin provides only the posix compatibility level between your program and the Windows kernel.

The situation is slightly worse on Linux. Wine can run native Windows code (without having to recompile anything, including source code). But Wine also has limitations. This is not a complete Windows API, and all that is required to run the library code must be available on Wine, otherwise it will not work. For many simple applications, this is not a serious problem, but many of the new Windows APIs, some dark corners of the older ones that do not see much use, and, in particular, everything related to the hardware will probably not be available.

If you intend to work on several platforms, it is very important to first make sure that the libraries you are going to use are also cross-platform or there are reasonable equivalents for all the operating systems that you want to use.

+5
source

No, Cygwin provides (partial) portability of the source code for * ix programs. Of course, there are higher-level tools that also provide portability to source code, such as QT and GTK. In any case, you still have to recompile the program and the library. For binary portability, you will need essentially the opposite of guilt, a program that understands ELF and maps the Linux system and library calls on Windows. As far as I know, this does not exist.

+3
source

Not. You must create it separately for Windows or Linux.

+1
source

There are several suggestions tailored to your situation:

  • Develop all the code for Windows, compile and run it.
  • On Linux, use the WINE emulator http://www.winehq.org/download/
  • If you decide to develop code on Linux, check out Windows SFU http://en.wikipedia.org/wiki/Microsoft_Windows_Services_for_UNIX
  • If possible, write to us what type of s / w you are trying to develop - third-party libraries such as boost [ http://www.boost.org] have a whole set of functionality that is independent of the platform. You definitely want to check out the options that gives you. Also check out other open source sites like github etc.
  • Do not use the familiar library on the platform. I know that they make life easier, but it is more than compensated when you need code on another platform.
0
source

Source: https://habr.com/ru/post/1315872/


All Articles