Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GCC from within VS 2005(8) IDE

Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE?

Our project is cross-platform, and I quite frequently get into trouble from my colleague because I'm checking in code that's not standards compliant (this can be attributed to the VS compiler!).

I'd still like to be able to compile using the MS compiler, so I can continue debugging, etc, however I'd like to be able to switch to compile using GCC, just so that I can be sure I'm not breaking the build on other platforms.

Is this possible?

like image 914
Alan Avatar asked Sep 15 '08 13:09

Alan


Video Answer


2 Answers

What I am about to suggest would still require a makefile, so I am partially repeating the advice from an earlier reply. Or, as was also mentioned earlier, maybe you already have a makefile, in which case you will have even fewer steps in order to accomplish what I am about to describe.

Once you know your specific windows command-line command for invoking make or g++ on your code, then you create a "Pre-Build Event" in your Visual Studio Project. ("Project Properties >> Configuration Properties >> Build Events >> Pre-Build Event").

The pre-build event can call a bat file script, or any other script on your machine, and that script will be able to return an error-code. Essentially, "script OK," or "script FAILED" is the extent of the amount of communication your script can have BACK to visual studio.

The script doesn't automatically see all the visual studio environment variables (such as $(InputDir), $(ProjectDir), $(SolutionName), etc), however you can use those variables when you specify how to call the script. In other words, you can pass those values to the script as arguments.

Set this up so that every time you build in Visual Studio, the pre-build event will FIRST try to run make/g++ on your code. If your script (the one that calls make/g++) detects any problems, then the script returns an error and the build can be STOPPED right then and there. The script can print to stdout or stderr and that output should be visible to you in the Visual Studio Build output window (the window that usually shows stuff like "========== Build: 3 succeeded, 0 failed").

You can have the script print:

"BUILD FAILED, non-portable code detected, make/g++ returned the following:........."

This way, you don't have to remember to periodically switch from Visual Studio to the command line. It will be automatically done for you every time you build.

like image 70
pestophagous Avatar answered Nov 15 '22 18:11

pestophagous


There are certainly ways to do this -- this is how we develop for the PS3 with sony's toolchain (which is based on gcc). I don't know exactly how that works, but it integrates pretty seamlessly into VS.

I think what you need to do is either set it up to build with a makefile (probably easiest) or to write a wrapper program that converts VC arguments to gcc ones. Also, if you want the error/warning output in the VS format (so you can click it and get that file/line up in the editor), you need something to convert the output.

This stuff may help you in a related discussion about using VS with WRS/VxWorks version of the gcc tools:

Especially note the program linked there which converts the error output.

like image 20
slicedlime Avatar answered Nov 15 '22 18:11

slicedlime