[英]Mac Terminal Compiling Errors
Note: I do have xcode installed as well as its command line tools. 注意:我确实安装了xcode及其命令行工具。
gcd.cpp:6:20: fatal error:
iostream
: No such file or directory gcd.cpp:6:20:致命错误:iostream
:没有这样的文件或目录
Is the error I get in terminal when running: 是我在运行时进入终端的错误:
g++ gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0 g ++ gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length = 0
I have no idea how to fix this issue. 我不知道如何解决此问题。 Any one know how to fix it? 谁知道怎么修它?
#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 更新
Running the command: 运行命令:
g++ -H gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0 g ++ -H gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length = 0
I now get this output(it will do the same error for sstream if I switch the order of it and iostream): 现在,我得到以下输出(如果切换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
You'll want to make sure that you have the Xcode command line tools installed. 您需要确保已安装Xcode命令行工具。 From the terminal run: 从终端运行:
xcode-select --install
More info: http://tips.tutorialhorizon.com/2015/10/01/xcrun-error-invalid-active-developer-path-library-developer-commandline-tools-missing-xcrun/ 更多信息: http : //tips.tutorialhorizon.com/2015/10/01/xcrun-error-invalid-active-developer-path-library-developer-commandline-tools-missing-xcrun/
Whenever I get stuck trying to figure out what the compiler did in Xcode, I always go to see what the command Xcode used was. 每当我试图找出编译器在Xcode中所做的事情时,我总是去查看Xcode使用的命令是什么。 In your project go to the Report navigator (should be on the left hand side, far right tab): 在您的项目中,转到“报告”导航器(应在左侧的最右边的选项卡上):
Then find the line for the file that you are interested in seeing further: 然后找到您有兴趣进一步查看的文件行:
Click on the little stack of pancakes on the far right to expand: 单击最右边的一小叠煎饼以展开:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.