Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate MinGW with Visual Studio 2010 (Makefile Project)

I'm trying to get MinGW (Version 4.7.2) working with Visual Studio 2010 to use some of the new C++11 features (sadly I'm still on WindowsXP and can't use Visual Studio 2012). To get started, I created a project with: File -> New Project -> Visual C++ -> General -> Makefile-Project

General:
Build Command Line: mingw32-make.exe
Rebuild All Command Line: mingw32-make.exe rebuild all
Clean Command Line: mingw32-make.exe clean all

IntelliSense:
Include Search Path: C:\MinGW\lib\gcc\mingw32\4.7.2\include\c++;C:\MinGW\include;
Assembly Search Path: C:\MinGW\lib\gcc\mingw32\4.7.2;C:\MinGW\lib;
Additional Arguments: -std=c++11

And I created an makefile with the content:

all:
    g++ -std=c++11 -pthread -o Makefile_Test.exe main.cpp

It compiles just fine, but almost everything is wavy red underlined in Visual Studios editor. i.e.

std::vector<std::thread> threads;

std::vector -> 'Error: namespace std has no member vector'

std::thread -> 'Error: namespace std has no member thread'

even std::cout << "";

std::cout -> 'Error: namespace std has no member cout'

But I included the correspondending headers of course: and Visual Studio can even find them (place the cursor at #include -> Ctrl+Shift+G opens the header). My MinGw folder looks like the following:

+ MinGW
|- bin
|- doc
|- include
|+ lib
 |- gettext
 |+ gcc
  |+ mingw32
   |+ 4.7.2
    |- debug
    |+ include
     |- c++
     |...
    |- include-fixed
    |- install-tools
|- libexec
|- mingw32
|- msys
|- share
|- var

I also tried to delete the sdf file a few times and let Visual Studio rebuild it from scratch - but all these errors appeared again.

Any ideas what I'm doing wrong here?

like image 899
Constantin Avatar asked Dec 27 '22 06:12

Constantin


2 Answers

I'm afraid you will have to give up your attempts to make those red squiggles disappear unless you disable them completely (so that, for instance, not even calls to non-existing functions will be marked).

The reason is that Visual Studio's Intellisense uses a separate front-end to EDG's C++ compiler to parse your program and possibly put a red squiggle under invalid statements or expressions, and the version used by Intellisense in VS2010 is (apparently) not fully compliant with C++11.

Therefore, switching to GCC 4.7.2 as the compiler will help building your C++11 programs, but won't affect the behavior of Intellisense.

If you want to disable the red squiggles completely, you can do it by selecting Tools -> Options -> Text Editor -> C/C++ -> Advanced, and setting "Disable Squiggles" to "True".

like image 147
Andy Prowl Avatar answered Dec 28 '22 20:12

Andy Prowl


Using the Makefile project template like OP described. I have been able to get VC 2013 & 2015 Community edition's intellisense working, by adding the proper include dirs to the projects properties.

  1. Open the Project menu
  2. Select {Project Name} Properties
  3. Open the Configuration Properties
  4. select VC++ Directories in the tree menu
  5. Add Directories to the Includes Directories section

You do have to add the directories that contain the items you want read into intellisense. Say I am working on a gtkmm project, I'd also include the glibmm dir so the Glib::ustrings didn't get squiggles. Even if glibmm.h is not directly included in my source files.

like image 38
cargo Avatar answered Dec 28 '22 20:12

cargo