C++ – How to port cli c++ program with GNU libraries from windows to Linux

clibrarieslinuxportabilitywindows

I need to implement some graph partitioning algorithms for my thesis. I have mostly Windows experience. I would like to know if it is hard to migrate c++ console program to Linux. I want to program it on Windows but I want to test and compile it on Linux as well. It will be pure cli application, with no use of windows APi or anything. I just need to use some external libraries. Specifically GNU linear programming kit and GNU scientific library GSL.
I found out, there are windows versions of these libraries, what does it mean for me?, should I compile it on Windows with windows version package and on Linux with linux package. I would like someone to bring a bit clarity to this, I am really not very experienced programmer, so any advice will help. Also I would like to ask, if there is diference if I use Visual Studio for programming or some other IDE in matter of portability issues. Thanks in advance for any help.

Best Answer

The first thing to remember is that, although C++ source code can be ported between Linux and Windows, the compiled binaries can't be exchanged (at least not without using emulation software).

To create a portable application, your best option is to stay with standard C++ code and portable libraries. For the libraries, you can either build them yourself from source or you can use pre-built versions. In the latter case, you should make sure that you install the same version of the library on each platform to avoid hitting incompatibilities due to the different versions.

To ensure your code stays portable and you don't accidentally start using compiler-specific constructs, I would advise you to regularly compile your code for both Windows and Linux. That way you will get an early warning instead of having a pile of work at the end.

Related Topic