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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2799789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:06:20  来源:igfitidea点击:

What C++ library do I need to get this program to compile

c++debuggingg++libraries

提问by neuromancer

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?

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

回答by asveikau

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 #includedoes is inserts a file into your code verbatim. It just so happens that the standard header fcntl.hwill have a line like:

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

#define O_RDWR    <some value here>

And unistd.hwill have lines like:

而且unistd.h将有像行:

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

int creat(const char *, mode_t);

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

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

The later linkingstep 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.

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

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

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

回答by James McNellis

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

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