开发者

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

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜