将MinGW与Visual Studio 2010集成(Makefile项目)(Integrate MinGW with Visual Studio 2010 (Makefile Project))

编程入门 行业动态 更新时间:2024-10-25 20:18:20
将MinGW与Visual Studio 2010集成(Makefile项目)(Integrate MinGW with Visual Studio 2010 (Makefile Project))

我试图让MinGW(版本4.7.2)与Visual Studio 2010一起使用一些新的C ++ 11功能(遗憾的是,我仍然在WindowsXP上,无法使用Visual Studio 2012)。 首先,我创建了一个项目: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

我创建了一个包含内容的makefile:

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

它编译得很好,但在Visual Studio编辑器中,几乎所有内容都以波浪红色加下划线。 即

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

std::vector - >'错误:命名空间std没有成员向量'

std::thread - >'错误:命名空间std没有成员线程'

甚至std::cout << "";

std::cout - >'错误:namespace std没有成员cout'

但是我当然包括了相应的标题:Visual Studio甚至可以找到它们(将光标放在#include - > Ctrl + Shift + G打开标题)。 我的MinGw文件夹如下所示:

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

我还尝试删除sdf文件几次,让Visual Studio从头开始重建 - 但所有这些错误再次出现。

我在这里做错了什么想法?

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?

最满意答案

我担心你将不得不放弃尝试使这些红色波浪线消失, 除非你完全禁用它们 (例如,甚至不会标记对不存在的功能的调用)。

原因是Visual Studio的Intellisense对EDG的C ++编译器使用了一个单独的前端来解析你的程序,并且可能会在无效语句或表达式下放置一个红色的波形,而VS2010中的Intellisense所使用的版本显然不完全符合C ++ 11。

因此,作为编译器切换到GCC 4.7.2将有助于构建C ++ 11程序,但不会影响Intellisense的行为。

如果要完全禁用红色波形,可以选择工具 - >选项 - >文本编辑器 - > C / C ++ - >高级,然后将“禁用斜角”设置为“真”。

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".

更多推荐

本文发布于:2023-08-07 00:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   Studio   MinGW   Visual   Project

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!