我正在使用 raspberry pi (ARM) 交叉编译 (host: x86 linux)
arm-bcm2708hardfp-linux-gnueabi-g++
当我选择 g++ 时,一切正常并编译。
但是当交叉编译时我得到:
error: 'close' was not declared in this scope
这是简化的源代码
#include <iostream>
#include <fcntl.h>
using namespace std;
int fd;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
close(fd);
return 0;
}
任何的想法?我忘记包括 smth 了吗?我使用 Eclipse 作为 IDE。
最佳答案
我相信就这么简单:close
声明于 <unistd.h>
,不是 <fcntl.h>
.要找出哪个头文件声明了符号,您应该始终首先查看手册页。
#include <iostream>
#include <unistd.h> // problem solved! it compiles!
using namespace std;
int fd;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
close(fd); // but explicitly closing fd 0 (stdin) is not a good idea anyway
return 0;
}
关于cross-compiling - 使用 fcntl.h : error: 'close' was not declared in this scope 的 ARM 交叉编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12159732/