57

I am creating a very large project (a few thousand lines) and so would rather not use Notepad++. An IDE would make it so much easier. I have experience with Microsoft Visual Studio and love it. Is there some easy way to use Cygwin's GCC from within Microsoft Visual Studio?

Alternately, are there any other good Windows IDEs for GCC besides NetBeans and Eclipse? (I hate both of them with a passion.)

Warren Young
  • 40,875
  • 8
  • 85
  • 101
MasterGberry
  • 2,800
  • 6
  • 37
  • 56
  • 2
    Hardly think so. GCC also exists for Windows as far as I am concerned. Apart from that, why would you use GCC? Do you need to do something Windows-specific? If so, Visual Studio would clearly be an advantage. – bash.d Feb 08 '13 at 12:52
  • Visual Studio can use makefiles. – Luke Feb 08 '13 at 14:42
  • The FTP client is going to be unix based, not windows based. I probably should have mentioned that in my question. – MasterGberry Feb 08 '13 at 17:02
  • http://www.visualgdb.com – Stuart Gillibrand Mar 05 '16 at 00:00
  • You can try Qt Creator. All members of my team dropped their eclipse installations after they saw it on my workstation. It can work with CMake (which supports gcc out of the box), Makefiles and their own QMake system (I would not recommend this one). – Rudi Mar 03 '18 at 17:33

3 Answers3

42

There are several ways to go here:

Option 1: Create a Custom Build Tool

Visual Studio 2005 and newer will let you register custom build tools. They tell the IDE how to transform files of one form (e.g. a .cpp file) into another form (e.g. an .obj file).

So far as I know, no one has done this yet for GCC. And, doing it yourself requires writing COM code, which is probably too deep a pool to dive into just for a single project. You'd have to have a compelling reason to take this project on.

You then have to manually adjust each project to tell it to use the custom build tool instead of the default, since you're using a file name extension (.cpp, probably) that Visual C++ already knows about. You'll run into trouble if you try to mix the VC++ and g++ compilers for a single executable built from multiple modules.

On the plus side, if you were looking to start an open source project, this sounds like a good one to me. I expect you'd quickly gather a big user base.

Option 2: Makefile Project

  1. Start Visual Studio and say File > New Project.

  2. In the Visual C++ section, select Makefile Project

  3. Fill out the Makefile Project Wizard:

    • Build command line: make
    • Clean commands: make clean
    • Rebuild command line: make clean all

You can leave the Output (for debugging) field alone if you've named your executable after the project name and it lands where Visual Studio expects to find it.

Leave the rest of the fields alone unless you know what they are and why you want to change them. As an example, you might choose to pass a -D flag on the Preprocessor definitions line to get separate debug and release outputs. If you know you want this, you know how to set it up, so I'm not going to make this long answer even longer in order to explain it.

You'll be asked the same set of questions for the Release build. If you want to bother with separate debug and release builds, you'd make any changes here.

Having done all this, you still have to create the Makefile, and add a make.exe to your PATH. As with the debug vs. release question, going into that level of detail would push this answer off topic.

As ugly as this looks, it's still easier than creating custom build tools. Plus, you say you need to port to Unix eventually, so you're going to need that Makefile anyway.

Option 3: Cross-Platform Development

You say you want to port this program to Unix at some point, but that doesn't mean you must use GCC on Windows now. It is quite possible to write your program so that it builds under Visual C++ on Windows and GCC/Makefiles on *ix systems.

There are several tools that make this easier. One very popular option is CMake, which is available as an installation time option in newer versions of Visual Studio. There are many alternatives such as SCons and Bakefile.

Warren Young
  • 40,875
  • 8
  • 85
  • 101
  • 1
    I'm pretty sure you can use the `nmake` tool supplied with Visual C++ and give it a rule for building with gcc. No need to find a third-party make. – Ben Voigt Feb 11 '13 at 21:19
  • 3
    @BenVoigt: Sure, but `Makefiles` written for [MS `nmake`](http://goo.gl/ZOD2g) (as opposed to [Bell Labs `nmake`](http://goo.gl/ZFoZH)) won't be portable to Unix, as the OP wants. MS `nmake` interprets commands as `cmd.exe` does, whereas POSIX `make` uses `/bin/sh` by default. So, an `rm` command in your `clean` target for a *ix `Makefile` has to be `del` in an `nmake` `.mak` file. On top of that, `nmake` is crippled compared to GNU and BSD make, which have taken over the *ix world. Plus, the OP already specified that he's using Cygwin. – Warren Young Feb 11 '13 at 21:38
  • 1
    @WarrenYoung Following Option 2, is it possible to step debug? I added my hello.cpp to the Source Files directory within Visual Studio, added a breakpoint, and hit F5. I am then informed that the exe and relevant cygwin dlls were built without symbols; while for Windows dlls: `Cannot find or open the PDB file`. – user2023370 Jan 03 '16 at 02:38
  • @user2023370: First, this is really a separate question, having to do with Visual C++, not Unix, Makefiles, or portability. At minimum, you need to add `/g` to your command line options to get a debug build. You might need a non-default `/M` option, too; RTFM. Second, trying to mix Visual C++ and Cygwin is probably a losing proposition from the start, if only because of the GPL license involved. If you want to use Cygwin, use Cygwin. If you want to use Visual C++ for Windows development instead, don't try to link in Cygwin. – Warren Young Jan 03 '16 at 03:04
  • 2
    CMake may help set up links and include folders for cross compile, but will not prevent you from using language features or libs that don't cross compile. – Denise Skidmore Jul 12 '16 at 17:00
  • 5
    Any update to that answer given Visual Studio 2015 / 2017? – Royi Mar 03 '17 at 11:18
  • Option 2 -- creating new Makefile project, no wizard shows in msvs 2019. – mireazma Mar 09 '21 at 14:16
7

Clang

You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.

If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project. Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS. Support for Android and iOS is included in the “Mobile Development with C++” workload. For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.

If you are targeting Windows, you have a few options:

  1. Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
  2. Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation). enter image description here

GCC

If your project targets Linux or Android, you can consider using GCC. Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang. You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.

enter image description here

Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC. If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.

Source: https://devblogs.microsoft.com/cppblog/use-any-c-compiler-with-visual-studio/

DevWhoDat
  • 92
  • 2
  • 6
4

I'm from the future.

I keep (poking at) a C/C++ toolchain using Visual Code on Win/Lin/Mac and MinGW installed from Choclatey. (This was done for my sanity - install GDB and GCC however you want)

I've run it with GCC and GDB with IntelliSense using MS's own weird JSON makefiles. Someday, someone (you?) will write a Gradle or Python script to generate these; for now the examples online in the docs seem to work.

It seems to require three types of JSON thing;

  • a single IntelliSense configuration for the whole workspace
  • a Debugging Configuration entry for each binary you want to debug
    • these can invoke the build tasks
  • a Build Task per-artifact
    • I don't think that there's a "require" or "dependency" thingie-mah-bob; sorry
pal
  • 942
  • 1
  • 9
  • 19