2017-01-24 29 views
0

注:xcodeとそのコマンドラインツールがインストールされています。Mac端末のコンパイルエラー

gcd.cpp:6:20: fatal error: iostream : No such file or directory

実行しているとき、私は、端末に取得エラーです:

g++ gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0

私はこの問題を解決する方法は考えています。どのようにそれを修正する方法を知っていますか?

#include <stdio.h> 
#include <iostream> 
#include <sstream> 

using namespace std; 

int gcdRecur(int a, int b) { 
    if(b == 0) 
     return a; 
    else  
     return gcdRecur(b, a % b); 
} 

int gcdIter(int a, int b) { 
    int z; 
     while(b != 0) { 
      z = b; 
      b = a%b; 
      a = z; 
     } 
     return a; 
} 

int main(int argc, char *argv[]) { 
    if(argc != 3){ 
     printf("Usage: %s <integer m> <integer n>", argv[0]); 
     return -1; 
    } 
    string m_str = (string) argv[1]; 
    string n_str = (string) argv[2]; 
    istringstream iss; 
    int m = 0, n = 0; 
    iss.str(m_str); 
    // Check if the first argument is an integer 
    // by giving the istringstream 0 
    if(!(iss >> m)){ 
     cerr << "Error: The first argument is not a valid integer." << endl; 
     return -1; 
    } 
    iss.clear(); 
    iss.str(n_str); 
    if(!(iss >> n)){ 
     cerr << "Error: The second argument is not a valid integer." << endl; 
     return -1; 
    } 
    int iter = gcdIter(m, n); 
    int recur = gcdRecur(m, n); 
    printf("Iterative: gcd(%d, %d) = %d\nRecursive: gcd(%d, %d) = %d\n", m, n, iter, m, n, recur); 
    fflush(stdout); 
} 

UPDATEコマンドを実行

g++ -H gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0

私は今、(私はそれの順序を切り替え、iostreamの場合、それはsstream提供のために同じエラーを行います)、この出力を得ます:

. /usr/include/stdio.h 
.. /usr/include/sys/cdefs.h 
... /usr/include/sys/_symbol_aliasing.h 
... /usr/include/sys/_posix_availability.h 
.. /usr/include/Availability.h 
... /usr/include/AvailabilityInternal.h 
.. /usr/include/_types.h 
... /usr/include/sys/_types.h 
.... /usr/include/machine/_types.h 
..... /usr/include/i386/_types.h 
.... /usr/include/sys/_pthread/_pthread_types.h 
.. /usr/include/sys/_types/_va_list.h 
.. /usr/include/sys/_types/_size_t.h 
.. /usr/include/sys/_types/_null.h 
.. /usr/include/sys/stdio.h 
.. /usr/include/sys/_types/_off_t.h 
.. /usr/include/sys/_types/_ssize_t.h 
+3

XCodeで定義済みのフラグを探します。標準ライブラリの実装のパスを指定する必要があるかもしれません。 –

+0

-Hフラグを付けて再度実行してください。すなわちg ++ -H test.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length = 0である。これにより、ヘッダファイルのロード時にプリプロセッサの試行が表示されます。それは何が起こっているのかを示すかもしれない。私のMacBookのiostreamはここにあります。 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream – ccpgh

+0

XCodeのg ++​​(実際にはclang)を使用していますか、自分でインストールしていますか? – molbdnilo

答えて

1

あなたは、Xcodeのコンマndラインツールがインストールされています。ターミナル実行から:

xcode-select --install 

さらに詳しい情報:http://tips.tutorialhorizon.com/2015/10/01/xcrun-error-invalid-active-developer-path-library-developer-commandline-tools-missing-xcrun/

私は、コンパイラがXcodeで何をしたかを把握しようとして動けなくなるたびに、私は常に使用されたコマンドXcodeのが何だったか見に行きます。

enter image description here

は、その後、あなたがさらに見ることに興味を持っているファイルの行を見つける:あなたのプロジェクトでは(左側、一番右のタブにする必要があります)レポートナビゲータに行きます右端のパンケーキの小さなスタック上enter image description here

クリックして拡大:

enter image description here

+0

えええええええええええええええええええええええええええええええええええ、私はそのメニューに行っていますが、Xcodeとターミナルでなぜ動作しているのか分かりません。 –

関連する問題