2

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?

Dellowar
  • 508
  • 3
  • 13
  • 1
    How did you debug under Linux? MinGW's GDB should provide you the very same possibilities. Any chance you forgot the debugging information (`-g`)? Also have you tried using Visual Studio instead? – Mario Dec 18 '16 at 07:47
  • @Mario I did not miss the build information for it's compiling with `-O0 -g3`. And does visual studio only do C++? Or is that the best way? – Dellowar Dec 18 '16 at 07:50
  • Visual Studio supports both C and C++ out of the box and is (IMO) the best way to debug programs you can compile due to all the visual helps, e.g. bring and to pin variable value displays/watch list entries right in your code. – Mario Dec 18 '16 at 07:56
  • @Mario Does visual studio support make files though? What is the windows equivalent? – Dellowar Dec 19 '16 at 20:33
  • Multiple ways, I'm posting this as an answer, since it's essentially a solution to your problem. – Mario Dec 20 '16 at 13:55
  • Cygwin exists to solve this problem. If you can just target Windows 10, the new Bash subsystem might be worth looking into. – Sean McSomething Dec 20 '16 at 20:35
  • @SeanMcSomething I thought Cygwin only built dependent binary. From my understanding running Cygwin built applications requires Cygwin. – Dellowar Dec 20 '16 at 20:36
  • @SanchkeDellowar Yes, but Sean was referring to the new Linux Subsystem that's part of Windows 10. It essentially allows you to ru native Linux executables on Windows (and build them as well). It wont solve your problem on accessing GPIO pins on the RPI though. – Mario Dec 20 '16 at 23:42
  • Are you asking primarily about what tools to use, or about how to port your code? – James Youngman Dec 21 '16 at 09:44

1 Answers1

1

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.).

Mario
  • 1,489
  • 2
  • 11
  • 13