當我從Xcode4.6運行以下代碼片段時,它編譯並運行正常。但是當我嘗試使用命令行工具(clang ++)編譯它時,它不能這麼做。構建在xcode 4.6中,但使用命令行失敗
#include <iostream>
#include <memory>
int main(int argc, const char * argv[])
{
std::unique_ptr<int> foo(new int(0));
// insert code here...
std::cout << "Hello, this is cool giri World!\n";
return 0;
}
這裏是編譯日誌:
$ clang --version Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix $ clang++ main.cpp -stdlib=libc++ -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/ -I /usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include/ main.cpp:7:10: error: no member named 'unique_ptr' in namespace 'std' std::unique_ptr foo(new int(0)); ~~~~~^ main.cpp:7:24: error: expected '(' for function-style cast or type construction std::unique_ptr foo(new int(0)); ~~~^ main.cpp:7:26: error: use of undeclared identifier 'foo' std::unique_ptr foo(new int(0)); ^ 3 errors generated.
嘗試'-std = C++ 11' – Pubby 2013-02-12 09:24:16
是的,我也嘗試過。相同的結果。 – user2061170 2013-02-12 09:37:10
'clang ++ -std = C++ 11'找不到'std :: unique_ptr'的定義,即使是'#include'也是如此。奇怪的編譯器。使用gcc。 –
Walter
2013-02-12 09:47:32