gpt4 book ai didi

c++ - 我需要什么 C++ 库来编译这个程序

转载 作者:IT老高 更新时间:2023-10-28 23:03:43 26 4
gpt4 key购买 nike

当我尝试编译我的程序时,出现以下错误:

btio.c:19: error: ‘O_RDWR’ was not declared in this scope
btio.c:19: error: ‘open’ was not declared in this scope
btio.c: In function ‘short int create_tree()’:
btio.c:56: error: ‘creat’ was not declared in this scope
btio.c: In function ‘short int create_tree(int, int)’:
btio.c:71: error: ‘creat’ was not declared in this scope

我需要包含哪些库来修复这些错误?

最佳答案

你想要:

#include <fcntl.h>    /* For O_RDWR */
#include <unistd.h> /* For open(), creat() */

另外,请注意,正如@R Samuel Klatchko 所写,这些是“库”。 #include 所做的是将文件逐字插入代码中。碰巧标准头 fcntl.h 会有这样一行:

#define O_RDWR    <some value here>

unistd.h 会有如下几行:

int open(const char *, int, ...);

int creat(const char *, mode_t);

换句话说,函数原型(prototype),它通知编译器该函数存在于某处,并且可以选择它的参数是什么样的。

随后的链接步骤将在中查找这些函数;这就是“库”一词的来源。最常见的这些函数将存在于一个名为 libc.so 的库中。您可以考虑您的编译器代表您插入标志 -lc(链接到 libc)。

此外,这些不是“C++”,而是 POSIX。

关于c++ - 我需要什么 C++ 库来编译这个程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2799789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com