views:

83

answers:

5

How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer.

Thank you.

+1  A: 

You may be able to make a custom makefile project to solve this for you.

Visual Studio's mainstream scenario is to be an IDE for MS developer tools. The more common ways to compile using GNU tools under Windows is MinGW or Cygwin.

Merlyn Morgan-Graham
A: 

As far as I know, there's no way to accomplish this. cl is more or less integrated with Visual Studio.

I guess if you were really desperate, you could try creating a pre-build step that invokes gcc and then doing something to stop the Visual Studio build from occurring.

dauphic
A: 

Use external build system. (Makefile project).

SigTerm
+4  A: 

You can't use the compiler directly.

You can, however, invoke a makefile instead of using the built-in build system.

Example of configuration:


  1. Install MinGW (I guess this step is already done), including mingw32-make
  2. Create a makefile for mingw32-make called MinGWMakefile , with 3 targets: clean, build, and rebuild. This can be very tedious if you've never done that before.
  3. Create a new configuration for your project
  4. Go to configuration properties->general->configuration type, and select "makefile"
  5. Go to configuration properties->NMake, and use these command lines:
    Build Command Line: mingw32-make -f MinGWMakefile build
    ReBuild Command Line: mingw32-make -f MinGWMakefile rebuild
    Clean Command Line: mingw32-make -f MinGWMakefile clean

Enable "go to line" functionality on compiler messages:


You need to transform the output of gcc, from this:

filename:line:message

To this:

filename(line):message

I was using a custom C++ program to do that, but any regular expression tool will do the trick.

Samuel_xL
A: 

For best results, use GNU make, a Visual Studio makefile project, and a tool that you write yourself. Your makefile is a skeleton, that compiles files (use a variable for the files list), and your tool parses the .sln and .vcproj files to generate this file list. The makefile includes the result. Just needs a bit of glue and elbow grease -- you'll spend a day cursing make's unwillingness to do what you want, then you'll get it working. Once up and running this approach doesn't require too much maintenance.

You can keep your tool and makefile simple, just throwing all files in all projects into the mix and linking the result, using file patterns to decide what happens to each file, and putting all compiler options in the makefile. Or you can get more clever, pull #defines and include paths from the project, and maybe add in a Win32 project configuration that the makefile generator uses to properly handle custom build steps, excluded files, compiler options, and so on.

The easy approach should satisfy most, because it lets anybody add new files to the project just as they normally do, without having to concern themselves with the makefile, whilst making it hard for people to accidentally change settings that don't want changing.

I have previously described this approach (with a tiny bit more detail):

http://stackoverflow.com/questions/593906/good-techniques-to-use-makefiles-in-visualstudio/670490#670490

(Once you have it set up, it works well, and in many respects it's actually more convenient than the usual VS approach, even before taking into account the fact you can now use other compilers.)

brone