首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fcntl编译C++问题

fcntl编译C++问题
EN

Stack Overflow用户
提问于 2009-11-16 15:33:25
回答 1查看 4K关注 0票数 1
代码语言:javascript
复制
{net04:~/xxxx/wip} gcc -o  write_test write_test.c
In file included from write_test.c:4:
global.h:10: warning: `b' initialized and declared `extern'

这段代码使用fcntl.h和定义的文件处理函数,如open()、write()、close()等。代码可以按预期进行编译和工作。

代码语言:javascript
复制
{net04:~/xxxx/wip} gcc -o  write_test write_test.cpp
In file included from write_test.cpp:4:
global.h:10: warning: `b' initialized and declared `extern'
write_test.cpp: In function `int main()':
write_test.cpp:56: error: `exit' undeclared (first use this function)
write_test.cpp:56: error: (Each undeclared identifier is reported only once for each function it appears in.)
write_test.cpp:58: error: `write' undeclared (first use this function)
write_test.cpp:62: error: `close' undeclared (first use this function)

当我把它作为CPP源码使用时,为什么GCC会抱怨?奇怪的是,它为什么不抱怨open()呢?这到底是怎么回事?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-11-16 15:51:56

  1. C++对头文件有更严格的要求--你需要:#include <unistd.h>来正确获取indicated.
  2. global.h不应该定义的函数,b- headers不应该初始化变量。
  3. 编译时您应该使用-Wall -Werror,这将迫使您修复代码中所有不可靠的部分。
  4. 要干净地获取exit(),您将需要#include <cstdlib> ( C++ )或#include <stdlib.h> (C)

< code >H115使用g++链接C++代码,以便包含C++库。用g++.完成整个C++编译可能是最简单的

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1740640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档