cross-compiling - 使用 fcntl.h : error: 'close' was not declared in this scope 的 ARM 交叉编译错误

标签 cross-compiling

我正在使用 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/

相关文章:

windows - 如何在 Windows 10 上交叉编译 Go 程序

c - 分析 ELF 部分和符号大小的工具

mips - busybox make 命令出错

java - sbt:避免 java 子项目中的多个组装/发布步骤

cross-compiling - 交叉编译 : How to install with one prefix, 并使用不同的前缀进行部署?

kernel - 在 amd64 主机上交叉构建 i386 linux 内核

linux - MIPS 的交叉编译器似乎无法创建有效的程序

python - 创建一个用于 Android 的 Python 库

cross-compiling - Meson交叉编译依赖

linux - 编译 GCC 并安装到 DESTDIR