Mac OS X 10.9 编译C++11

Notice: How to compile C++ with C++ 11 support in Mac Terminal

stackoverflow上面的问题

其实mac里面的不是g++而是clang 我们输入:

g++ --version查看

其实是clang

so linux下的g++ -std=c++11是无效的

那我们我们怎么编译呢?

我们可以用下面的命令行:

clang++ -std=c++11 -stdlib=libc++ -Weverything main.cpp

如果你没有安装Xcode的话你可以用xcrun命令工具:

xrcun clang++ -std=c++11 -stdlib=libc++ -Weverything main.cpp

eg:

$ vi t.cpp
#include <iostream>

int main()
{
    int* p = nullptr;
    std::cout << p << std::endl;
}
$ clang++ -std=c++11 -stdlib=libc++ -Weverything t.cpp
$ ./a.out 
0x0

 

 

-Weverything was initially built for two reasons:

  • discovery: it's pretty hard otherwise to get a list of all available warnings
  • black-listing alternative: with gcc, you cherry pick the warnings you wish to apply (white-listing), with -Weverything you cherry pick those you do not wish to apply; the advantage is that when moving over to a new version of the compiler, you are more likely to benefit from new warnings

摘自 http://stackoverflow.com/questions/14181789/how-to-use-clang-with-std-c11-weverything-werror 

转载于:https://www.cnblogs.com/134feilei/p/3843782.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值