您的位置:首页 > 编程语言 > C语言/C++

Mac OS 下g++(c++)编译工具无法使用

2015-04-16 16:32 197 查看
最近在Mac OS上做C++ 开发,却遇到一个让人难以费解的问题。g++工具无法编译c++源码,提示找不到__debug文件(这个文件我也不知道是做什么用的,有知道的希望各位高手们能指点一下)。其实源码很简单,就是简单的Hell World。

#include<iostream>

using namespace std;

int main(){

cout << "Hello World!" << endl;

return 0;

}

kevindeMacBook-Air:namespace kevin$ g++ hello.cpp

In file included from hello.cpp:1:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:439:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:604:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:341:10: fatal error: '__debug' file not found

#include <__debug>

         ^
1 error generated.

发现上述问题后,baidu了the question,但是没有结果。然后在google上找到了一个凑效的解决方法(但作者没有说明解决的缘由)

kevindeMacBook-Air:namespace kevin$
echo '#define _LIBCPP_ASSERT(x, m) ((void)0)' | sudo tee -a
/Library/Developer/CommandLineTools/usr/include/c++/v1/__debug > /dev/null

Password:

kevindeMacBook-Air:namespace kevin$ g++ hello.cpp

kevindeMacBook-Air:namespace kevin$ ./a.out
Hello World!

感觉作者是创建了一个__debug 文件并在其中写入了相应的内容,但是如果是这样的话,那g++工具在安装的时候就没有这个文件吗?实在不明白怎么回事。 这里只把一种解决方法贴出来,希望能帮到跟我一样的人。如果有人知道这个方法的原理,烦请告知,不胜感激
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: