使用fcntl.h的ARM交叉编译错误:错误:在此范围内未声明'close'

时间:2012-08-28 12:56:37

标签: cross-compiling

我正在使用

交叉编译(host:x86 linux)for raspberry pi(ARM)
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。

1 个答案:

答案 0 :(得分:33)

我认为这很简单: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;
}