{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()等。代码可以按预期进行编译和工作。
{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()呢?这到底是怎么回事?
发布于 2009-11-16 15:51:56
#include <unistd.h>来正确获取indicated.global.h不应该定义的函数,b- headers不应该初始化变量。-Wall -Werror,这将迫使您修复代码中所有不可靠的部分。exit(),您将需要#include <cstdlib> ( C++ )或#include <stdlib.h> (C)< code >H115使用g++链接C++代码,以便包含C++库。用g++.完成整个C++编译可能是最简单的
https://stackoverflow.com/questions/1740640
复制相似问题