How do I set GNU G++ compiler in Visual studio 200

2019-03-30 15:38发布

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.

5条回答
我只想做你的唯一
2楼-- · 2019-03-30 16:07

Use external build system. (Makefile project).

查看更多
男人必须洒脱
3楼-- · 2019-03-30 16:09

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.

查看更多
仙女界的扛把子
4楼-- · 2019-03-30 16:14

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.

查看更多
我想做一个坏孩纸
5楼-- · 2019-03-30 16:14

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

Good techniques to use Makefiles in VisualStudio?

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

查看更多
小情绪 Triste *
6楼-- · 2019-03-30 16:22

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.

查看更多
登录 后发表回答