problemas fcntl compilando c ++
Pregunta
{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'
Este código usa fcntl.h y las funciones de manejo de archivos definidos - como open (), write (), searn () etc. El código compila y funciona según lo previsto.
{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)
Cuando lo uso como código fuente de CPP, ¿por qué GCC se queja? Y curiosamente, ¿por qué no se queja para Open ()? ¿Qué está pasando aquí?
Solución
C ++ es más estricto sobre los encabezados, necesitas:
#include <unistd.h>
Para obtener correctamente las funciones indicadas.global.h
No debe definir B - Los encabezados no deberían inicializar variables.Al compilar deberías usar
-Wall -Werror
Y eso te obligará a arreglar todos los bits dudosos de tu código.Llegar
exit()
limpiamente necesitarás#include <cstdlib>
(C ++) o#include <stdlib.h>
(C)Usar
g++
para vincular el código C ++ para que se incluyan las bibliotecas C ++. Probablemente más fácil de hacer la compilación completa de C ++ cong++
.