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

发布于 2024-08-31 12:15:41 字数 405 浏览 6 评论 0原文

当我尝试编译程序时,出现这些错误:

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

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

When I try to compile my program I get these errors:

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

what library do I need to include to fix these errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪 2024-09-07 12:15:41

您想要:

#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);

换句话说,函数原型,它通知编译器认为该函数存在于某处,并且可以选择其参数的样子。

后面的链接步骤将在中查找这些函数;这就是术语“库”的由来。最典型的是,这些函数将存在于名为 libc.so 的库中。您可以认为您的编译器代表您插入了标志 -lc(链接到 libc)。

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

You want:

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

Also, note that, as @R Samuel Klatchko writes, these are not "libraries". What #include does is inserts a file into your code verbatim. It just so happens that the standard header fcntl.h will have a line like:

#define O_RDWR    <some value here>

And unistd.h will have lines like:

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

int creat(const char *, mode_t);

In other words, function prototypes, which informs the compiler that this function exists somewhere and optionally what its parameters look like.

The later linking step will then look for these functions in libraries; that is where the term "library" comes in. Most typically these functions will exist in a library called libc.so. You can think of your compiler inserting the flag -lc (link to libc) on your behalf.

Also, these are not "C++" but rather POSIX.

清引 2024-09-07 12:15:41

您尝试过吗?搜索这些符号的任何组合都会产生......

Have you tried <fcntl.h>? A search for any combination of those symbols would have yielded that...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文