How to Build a Linux C Project on Windows

ccross platformgtkwindows

I recently completed a C project that uses GTK and OpenSSL. I have native binaries in linux and they run just great. However my new goal is to make as close to native as I can with a build for windows.

I've tried MinGW and it produces as a exe, however it crashes very easily, and gdb performs poorly when attempting to debug windows builds. It's almost pointless to try to make sense of the binary mess.

So I'm in search of any alternative solutions or perhaps an improved version of this one. How do I build a Linux C project on windows?

Best Answer

It depends heavily on your approach.

My preferred way is to use CMake to create project files or makefiles based on the current platform. For example, under Linux this would create classic makefiles, while under Windows it would create a VS project. You still only have to maintain the CMake source file(s).

In your case I'd have a look at the Linux Tools for VS extension, considering you can't really debug the GPIO pins on your Windows machine. Further details are in the linked blog post, since this is a bit lengthy to explain and setup. The usage is rather trivial though.

This essentially prepares Visual Studio to only act as a remote IDE. When issuing a build command or starting a debug run, it will upload modified files through SSH, issue the build commands and then connect to the GDB server to perform debugging, everything with the known tools and features from Visual Studio (e.g. visual debugging, watch list, etc.).

Related Topic