0

I have a c++ code written and compiled on Linux is there any way that I compile it on Linux and get it working on windows?

the extra library used is jsoncpp.

  • 1
    In order to be able to do that you need more than a compiler, but also all the header and other development files that are used to build stuff on MS-Windows. Basically all the header files from VC. I never heard of anything like that. Doesn't mean that it doesn't exist, somewhere, but I doubt it. – Sam Varshavchik Jan 10 '21 at 16:08
  • 2
    What you need is to *cross-compile* your program. IIRC you can use MinGW in the Linux environment to cross-compile for Windows. – Some programmer dude Jan 10 '21 at 16:09
  • 2
    Why not use a virtual machine? – Aykhan Hagverdili Jan 10 '21 at 16:09
  • 1
    Related: [https://stackoverflow.com/questions/15986715/how-do-i-invoke-the-mingw-cross-compiler-on-linux](https://stackoverflow.com/questions/15986715/how-do-i-invoke-the-mingw-cross-compiler-on-linux) – drescherjm Jan 10 '21 at 16:11
  • You should look at cross compilers – cmdLP Jan 10 '21 at 16:13
  • Why do you overcomplicate things? Visual Studio Community (Windows) is free and can compile the source code for Windows. Use a virtual machine if you don't have a Windows box. – StureS Jan 10 '21 at 16:14
  • 1
    Pardon the obvious question but *why*. jsoncpp can easily be built on Windows using cmake and any number of toolchains targeting that platform. Or did I just misunderstand the real problem? – WhozCraig Jan 10 '21 at 16:15
  • Note that cross-compilation is only *one* (and rather small) part of writing platform-portable code. If you use anything but standard C++ with only terminal output, then you also need to rewrite the platform-specific parts of your code. – Some programmer dude Jan 10 '21 at 16:15
  • you can either use mingw or run visual studio under wine – Alan Birtles Jan 10 '21 at 16:28

2 Answers2

1

With recent versions of windows you also have the option of the Windows Subsystem for Linux (WSL) and may be able to simply run a native linux binary.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
0

use mingw on linux it will install the required sdk (headers and libraries) to develop apps for windows and it will do the cross platform compilation. Another advantage is that it is a gcc port for windows so you will be familiar with as gcc is widely used on linux

dev65
  • 1,440
  • 10
  • 25