Cygwin gcc compiled a crash in the IDE complaining of an "exit" undeclared

When I compile a program using only

gcc code.c

There are no messages, and the output file was generated successfully. The output file works. However, when I try to install the same cygwin gcc compiler component in the IDE (I tried Netbeans and Dev-C ++), I get the following errors:

main.cpp:27: error: `exit' undeclared (first use this function)
main.cpp:27: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:77: error: `write' undeclared (first use this function)
main.cpp:78: error: `close' undeclared (first use this function)

I do not understand what is different. Why doesn't it compile?

OK, the problem is that in the IDE, the file had the extension .cpp, whereas when I compiled from the terminal, it had the extension .c. So my new question is why it does not compile when it is processed as a C ++ file. Is C a subset of C ++?

+3
4

++ , C. C , ++ .

, :

#include <stdlib.h>

, . -Wall, :

gcc -Wall code.c
+5

IDE . :

#include <stdlib.h>  // exit()
#include <unistd.h>  // close(), write()

, C. , IDE "-Wmissing-prototypes" .


++, , . C sloppier ( sloppier) - , , . ++ .

C, ++; C, ++, ++, C. , C-, , ++. , C "exit()", . ++ 'exit()', .

+1

g++ .cpp.

0

One of the possible reasons may be that the IDE cannot access the included files, the cygwin gcc compiler can expect it /usr/include(not sure), and dev-cpp may not have access to it.

0
source

Source: https://habr.com/ru/post/1731789/


All Articles