0
我對我與Sierra和Xcode9.0.1塞拉利昂,cpp命令可拋「的iostream」找不到文件
我編譯克以下的Hello World代碼的MacBook Pro之後的tutorial ++沒有問題。
#include <iostream>
main() {
using namespace std;
cout << "Hello, World!" << endl;
}
但是,當我執行
cpp hello.cxx | more
所要求的教程中,我得到了以下錯誤消息:
hello.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
# 1 "hello.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 330 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "hello.cpp" 2
'cpp'命令是預處理器。它本身可能不知道系統頭文件的位置。您可能需要使用'-I'(大寫的i)選項來指定系統頭文件搜索路徑。 –
谷歌搜索後,我發現['cpp'](http://www.tutorialspoint.com/unix_commands/cpp.htm)是Linux中的c預處理器的名稱,可能也在OS/X中。 (因爲它只進行預處理(例如,以'#'爲前綴的語句),它也可以用於C++文件。)也許,你可以嘗試'man cpp'來了解更多信息。它可能沒有默認的正確包含目錄。要檢查這個,你可以嘗試'cpp -I'和文件'iostream'所在的路徑。 – Scheff
謝謝,所以下面你的評論我試過這個:cpp -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream hello.cpp 但是得到了: 鐺:error:no such file or directory:'c' clang:warning:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:'linker'input unused [ -Wunused的命令行參數的] – BlackSwing