我有一个基本程序,用于比较两个字符串:
#include <string>
#include <iostream>
using namespace std;
int main (int argc, char *argv[]) {
if(strcmp (argv[0],"./test") != 0) {
cout << "not equal" << endl;
} else {
cout << "equal" << endl;
}
return 0;
}
使用gcc编译可以,但使用clang编译不行:
> clang -o test test_clang.cpp
test_clang.cpp:7:6: error: use of undeclared identifier 'strcmp'
if(strcmp (argv[0],"./test") != 0) {
^
1 error generated.
为什么使用clang编译会失败?编辑:人们在stackoverflow上变得非常苛刻,以至于我犹豫是否要发布一个问题。上面的问题有一个简单的答案,但是因为它具有简单但不明显的答案,下降问题(在第一分钟内下降两次!)是否正常?