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

neu*_*cer 12 c++ debugging g++ libraries

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

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
Run Code Online (Sandbox Code Playgroud)

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

asv*_*kau 36

你要:

#include <fcntl.h>    /* For O_RDWR */
#include <unistd.h>   /* For open(), creat() */
Run Code Online (Sandbox Code Playgroud)

此外,请注意,正如@R Samuel Klatchko所写,这些不是 "图书馆".什么#include是逐字地将文件插入到您的代码中.恰好,标准标题fcntl.h会有如下行:

#define O_RDWR    <some value here>
Run Code Online (Sandbox Code Playgroud)

而且unistd.h将有像行:

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

int creat(const char *, mode_t);
Run Code Online (Sandbox Code Playgroud)

换句话说,函数原型通知编译器该函数存在于某处,并且可选地其参数如何.

然后,后面的链接步骤将在库中查找这些函数; 这就是术语"库"的用武之地.大多数情况下,这些函数将存在于一个名为的库中libc.so.你可以想到你的编译器代表你插入标志-lc(链接libc).

而且,这些不是"C++"而是POSIX.

  • @Phenom - 请再次阅读我的回答.该库具有实际代码.标头是未编译的C,它具有没有实现的声明. (3认同)

Jam*_*lis 6

你试过<fcntl.h>吗?搜索这些符号的任何组合都会产生......

  • @Phenom:`creat`或`O_RDWR`的第一个结果来自OpenGroup POSIX文档...... (3认同)