Eclipse C compilation not working - c

I downloaded Eclipse C/C++ for windows. Unfortunately i compile and start this code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
First all i got this: symbol stdio.h stdlib.h and exit_succes can not be resolved.
After i tried to build it i cant even run it. WHen i run it straight i got this 4 errors:
> -Program "g++" not found in PATH(Scanner)
> -Program "gcc" not found in PATH(Scanner)
> -Program "make" not found in PATH(Problem)
> -Symbol 'EXIT_SUCCES'could not be resolved (Semantic Error)
Can anybody tell me what's wrong? I would be grateful for any help.

Eclipse is not a compiler, and apparently you don't have the compilers eclipse is expecting installed, so it complains. I think the first choice for a compiler on windows is gcc from minGW.
The last error simply means that EXIT_SUCCES is not defined. I think you mean EXIT_SUCCESS, but that is just a guess.

Related

Why is only the reference to endwin() not defined, when compiling this example code for PDCurses?

When compiling the example hello-world.c for PDCurses, the linker can't seem to find the endwin() function only. Commenting out the line containing endwin(), the code compiles fine and the program runs.
Here's the example code, taken from here (from source/pdce0.c):
#include <curses.h>
/* hello world, initialize curses */
int main()
{
initscr();
printw("Hello World !!!");
refresh();
getch();
endwin();
return 0;
}
When compiling using the mingw64 shell, the following error get's thrown
$ gcc -W -Wall -Ic:/Tools/msys64/mingw64/include/pdcurses -o test hello-world.c -lpdcurses
C:/Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Tools\msys6
4\tmp\ccsKgZ37.o:hello-world.c:(.text+0x39): undefined reference to `endwin_x64_4302'
collect2.exe: error: ld returned 1 exit status
As stated above, commenting out endwin() in the code leads to compilation without error.
My setup is a MSYS2 installation on Win10 and I installed the mingw64 toolchain and PDCurses for mingw64 according to the steps described by the MSYS doc and this question.
I tried linking the curses lib in different ways, -lncurses, -llibpdcurses, but this does not help.
I tried the curses.h found in the above stated GitHub repo, it looks much simpler, but all this does is change the error to undefined reference to 'endwin'.
Edit 1 regarding comments
Concerning the internal definition of endwin() as a macro, I found this part in the include\pdcurses\curses.h
#ifdef PDC_WIDE
#ifdef PDC_FORCE_UTF8
#ifdef CHTYPE_32
#define endwin endwin_u32_4302
#else
#define endwin endwin_u64_4302
#endif
#else
#ifdef CHTYPE_32
#define endwin endwin_w32_4302
#else
#define endwin endwin_w64_4302
#endif
#endif
#else /* 8-bit chtypes */
#ifdef CHTYPE_32
#define endwin endwin_x32_4302
#else
#define endwin endwin_x64_4302
#endif
#endif
A comparable definition is not included in the curses.h from the examples repo.
Still, endwin() doesn't seem to be defined in the lib.
I already tried reinstalling the pdcurses package via pacman, but everything seems to be fine on that end.
Could using another of the MSYS shells or another package be of help? I'll see what I can find out.
Edit 2
I just took a look at some of the other examples and found out, that adding an infinite loop like
int main()
{
initscr();
printw("Hello World !!!");
while(1){
refresh();
}
getch();
endwin();
return 0;
}
also compiles without the error, but of course produces an unresponsive program.
I have to add that I'm rather new to C, compiling and everything, so if this problems requires some further reading, I'd be glad about suggestions.
Using #include <pdcurses.h> lets it compile without error (this is kinda the direction, John Bollinger mentioned in his comment). I found this issue on the MSYS2/MINGW-Packages GitHub, leaving the impression, that my installation/build version of pdcurses might need some attention. Like one of the commenters there, I thought, that linking against pdcurses didn't need changes of the included headers. I'll look into the setup more thoroughly.
But just to get started and try some things out, everything seems to work for now.

fatal error: studio.h: no such file or directory

I'm trying to learn how to program in C.
I'm simultaneously learning C, C++, & Java. I have also coded in html and javascript successfully making rich websites.
I'm following video lessons on skillshare. Through VirtualBox I've set up a ubuntu installation, created lesson001.c, and attempted to compile it by entering "gcc lesson001.c"
The program:
#include <studio.h>
int main(){
printf("hello, world!\n");
return 0;
}
The error:
lesson001.c:1:10 fatal error: studio.h: no such file or directory.
The instructor is walking through the coding lesson on a pre-configured linux system, so he does have the same errors. It is frustrating that a comprehensive paid lesson set does not include critical setup parameters.
additional info: "gcc -v" returns about 20 lines of information on gcc 9.3.0, so I believe it is installed correctly.
Thank you
Change the #include <studio.h> declaration to #include <stdio.h>. A header file named studio.h does not exist in the standard library.
stdio stands for "standard input/output," and has nothing to do with "studio"! 😀
It should be stdio instead of studio.
stdio stands for Standard Input Output
Correctly formatted code :
#include <stdio.h>
int main(){
printf("hello, world!\n");
return 0;
}

Code::Blocks 13.12 error - CC1.exe has stopped working

I am using Code::Blocks 13.12 for programming in C. After building and running my simple HelloWorld.c program, it gives an error.
Error: An alert box pop up saying -"cc1.exe has stopped working.A problem caused the program to stop working correctly.Windows will close the program and notify you if a solution is available."
I tried using Notepad++ , the same pop up appears saying a.exe has stopped working.
I am a naive,so have no idea on how to deal with this.
My queries:
1) Am I using an outdated version? If not, how can I get rid of this problem?
2) Which is the most efficient IDE available for C/C++ if Code::Blocks is not that efficient?
My requirement"
-I had been using Turbo C and it doesn't give errors like segmentation fault and other memory related errors that we get in online Compilers or compilers of competitive programming.So, I need an efficient compiler which behaves same as online compilers, so I don't get stuck while solving problems during competitive programming.
This is the simple code giving error:
#include <stdio.h>
void main()
{
printf("Hello world!");
//return 0;
}
Edit:
Even after changing the code to return int, it's giving an error.I tried editing the code as below, but the same window is being popped up again.
int main(void)
{
printf("Hello world!");
return 0;
}
There's no problem with your code, though indeed, as pointed out in the comments, neither void main() nor int main(void) is considered correct, but that's not what's causing the problem. cc1.exe is a MinGW-related file (MinGW is the GCC port for Windows that Code::Blocks uses by default for compilation); if it's crashing, it's possible the installation is corrupt.
I suggest you try reinstalling MinGW - remove Code::Blocks, install the standalone MinGW version, then download Code::Blocks without the compiler suite, install it and configure to use your version of MinGW.
For me, the solution was to choose,
Select target -> Release
from the Build menu. It took lots of time for me to find this!

Correct command line parameters for gcc compilation of SDL

I recently started SDL2.0 programming.
I did a lot of researches and i tried all but i still get those "undefined reference" errors for all the SDL functions:
undefined reference to `SDL_Init'|
undefined reference to `SDL_GetError'|
undefined reference to `SDL_Quit'|
||=== Build finished: 3 errors, 0 warnings ===|
on that simple test program:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
If i have to guess the problem occurs due to the wrong command line syntax.
In this case what should be the correct one?
You aren't linking to the SDL libraries correctly.
Add the following lines int Other Linker Option
-lSDL -lSDLmain
mingw32
SDLmain
SDL
Also You need to check setup for how to compile SDL in codeblock
http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks
http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/
If it's not too late then try from the beginging to how to set up SDL in codeblock and successfully run it? Below link provide you exact steps for it.
http://www.dreamincode.net/forums/topic/57275-setting-up-codeblocks-to-work-with-sdl/
You might have not linked SDL2 correctly to your CodeBlocks project and not referred to SDL2 correctly in your code.
1:
Go to "Linker options" in "Build Options" menu and make sure you have added these library's to your project like this:
Library's to include in linker options
Importent!: save project before running it after adding/changeing library's.
2:
Change:
#include "SDL.h"
to this:
#include <SDL2/SDL.h>
if you still encounter problems compiling and running it, it's most likely either, your SDL2 files not placed correctly in the compiler's folders, or your using an version of gcc with some missing tools.
These Youtube video's explain everything in great detail:
1: https://www.youtube.com/watch?v=x0LUf7Ibpi0
2: https://www.youtube.com/watch?v=EtUw_7CvRRo

sockets.h problem with cygwin and eclipse

I keep getting this error:
c:\cygwin\usr\include/cygwin/socket.h:55:3: error: expected specifier-qualifier-list before '__uid32_t'
My code is mininmal and still can't compile:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
I have include C:\cygwin\usr\include to compiler path and linker to C:\cygwin\usr\lib
please advise
Headers under C:\cygwin\usr\include, and libraries under C:\cygwin\usr\lib, are for use in the Cygwin environment -- which means they should be referred to via their Cygwin paths, /usr/include and /usr/lib.
I haven't used mingw, but I don't think it's part of Cygwin, and I wouldn't expect it to be able to use Cygwin's headers and libraries.
If you're going to use mingw, you should use the headers and libraries that are installed with it. Don't specify any Cygwin-related directories.
Or you can use Cygwin's gcc (which is optional; you'll have to install it with setup.exe). In that case, you can run gcc or make from the command line. I'm not sure whether Cygwin and Eclipse play nicely together.
I know this question is old, and I'm using a newer version, but I had a similar issue and it was resolved by moving #include <sys/socket.h> one line above #include <sys/types.h>.
Something in types.h appears to be blocking socket.h (not sure how). Wish I had more details on the cause, but hope the solution helps some.

Resources