0

I've been tasked with writing an application that conditionally compiles to a Win32 GUI application under Windows, or a console application under Linux.

My biggest stumbling block so far is just figuring out how to setup this project. I typically work in Visual Studio 2012 and when creating a new C++ Win32 project have the choice between a console app and a GUI app. I feel like this is setting some project properties and stuff related to the compiler that's going to make it difficult to compile the same project under Linux and have it generate a console application.

The conditional compilation stuff I'm not terribly concerned about, I'm just trying to figure out if I should be compiling this stuff through the command line on Windows rather than using Visual Studio, and how I would be setting the target application to end up as a GUI or console app when doing this.

Hopefully I've explained myself clearly, I think it's obvious I'm pretty lost. Thanks in advance for any help.

3 Answers3

3

This seems like one of those situations where you'd be better served by making a library containing the bulk of the functionality, then two or three frontends to that library to expose its functionality as a console app or GUI program.

No sense in trying to bash a bunch of Win32 GUI stuff into what is otherwise a console app project.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
0

I would recommend using a cross-platform toolkit such as wxWidgets or Qt. That way you are not tied to one specific platform architecture. Those frameworks also have extensive documentation about how to set up a project correctly with a variety of compilers/development environments.

0

This is something that you can, at least on the windows side, use preprocessor definitions for the project to define both. Discussed here!

C++ compiling on Windows and Linux: ifdef switch

and stylize your code sections as:

#ifdef WIN32   // Windows system specific
#include <windows.h>
#else          // Unix based system specific
#include <sys/time.h>
#endif

Continue to separate all of your cross platform code this way. Don't forget to add WIN32 to your project properties under Properties --> Configuration Properties --> C/C++ --> Preprocessor

Community
  • 1
  • 1
physincubus
  • 986
  • 2
  • 11
  • 26