Author Topic: Code::Blocks forces C++ compiler  (Read 3147 times)

Offline Casto_Dailla

  • Single posting newcomer
  • *
  • Posts: 3
Code::Blocks forces C++ compiler
« on: May 27, 2019, 04:13:02 pm »
Long story short, I'm writing a project in C, but for some reason Code::Blocks does not let it compile and run, despite the fact that the code is perfectly valid (or not, imma newb so don't hesitate to correct me).
Generally when creating new projects, I used console app, sometimes disabling the console if I decided to use some GUI. This time I started with "Empty Project", and pretty much everything went right - until I noticed that C::B applies C++ restrictions to my code, even though I'm writing entirety of the code in C, selected GCC compiler in build options for the project and even specified C99 standard in compiler flags.
Exact errors attached.

What I'm trying to do is to use arrays of dynamically specified size (instead of being specified in the code, or as a global variable, they should be passed as an argument to the funcion). It worked before in console apps (which, by the way, forced me to choose whether it was C or C++, guess now I know why), now it doesn't, and I doubt I have the time to make a workaround.

While it's technically a code problem, I'm pretty sure I can "fix" it by simply setting the Code::Blocks to apply correct compiler logic to the code, as it's already been proven to work.
Any help appreciated, thanks in advance. Looked on web, but all of the topics seem to be about the opposite - forcing C++ format/compiler instead of C.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1563

Offline Casto_Dailla

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code::Blocks forces C++ compiler
« Reply #2 on: May 27, 2019, 05:09:15 pm »
Build log:
Code
-------------- Clean: Debug in Knight's Tour (compiler: GNU GCC Compiler)---------------

Cleaned "Knight's Tour - Debug"

-------------- Build: Debug in Knight's Tour (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -std=c99 -g -std=c99 -I"..\..\CSFML 2.5\include" -I"..\..\CSFML 2.5\include" -c "F:\C\Knight's Tour\knight.c" -o obj\Debug\knight.o
mingw32-gcc.exe -Wall -std=c99 -g -std=c99 -I"..\..\CSFML 2.5\include" -I"..\..\CSFML 2.5\include" -c "F:\C\Knight's Tour\MAIN.C" -o obj\Debug\MAIN.o
mingw32-g++.exe -L"..\..\CSFML 2.5\lib" -L"..\..\CSFML 2.5\lib" -o "bin\Debug\Knight's Tour.exe" obj\Debug\knight.o obj\Debug\MAIN.o   -lcsfml-graphics -lcsfml-audio -lcsfml-window -lcsfml-system -lcsfml-graphics -lcsfml-audio -lcsfml-window -lcsfml-system -mwindows
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++
F:\C\Knight's Tour\knight.c: In function 'Knight_Main':
F:\C\Knight's Tour\knight.c:283:20: warning: passing argument 1 of 'show_board' from incompatible pointer type [-Wincompatible-pointer-types]
         show_board(t->board, t->SIZE); ///Pokazanie rozwiazania, jezli istnieje
                    ^
F:\C\Knight's Tour\knight.c:58:13: note: expected 'const int **' but argument is of type 'int **'
 static bool show_board(const int ** Board, const int Size)
             ^
In file included from F:/CSFML 2.5/include/SFML/Window/Window.h:32:0,
                 from F:/CSFML 2.5/include/SFML/Window/Context.h:33,
                 from F:/CSFML 2.5/include/SFML/Window.h:34,
                 from F:/CSFML 2.5/include/SFML/Graphics.h:32,
                 from F:\C\Knight's Tour\MAIN.C:2:
F:/CSFML 2.5/include/SFML/Window/Event.h:132:3: warning: '._20' is deprecated [-Wdeprecated-declarations]
 } sfMouseWheelEvent;
   ^
F:/CSFML 2.5/include/SFML/Window/Event.h:127:1: note: declared here
 {
 ^
F:\C\Knight's Tour\MAIN.C: In function 'int main()':
F:\C\Knight's Tour\MAIN.C:69:53: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     sfRenderWindow * window = sfRenderWindow_create({SPRITE_RES * SIZE,
                                                     ^
F:\C\Knight's Tour\MAIN.C:79:29: error: cannot convert 'tile (*)[8]' to 'tile**' for argument '2' to 'void create_tiles(int, tile**)'
     create_tiles(SIZE, tiles);
                             ^
F:\C\Knight's Tour\MAIN.C:80:40: error: cannot convert 'tile (*)[8]' to 'tile**' for argument '2' to 'void set_tiles(int, tile**, sfTexture*)'
     set_tiles(SIZE, tiles, tile_texture);
                                        ^
F:\C\Knight's Tour\MAIN.C:92:39: error: cannot convert 'tile (*)[8]' to 'tile**' for argument '3' to 'void draw_tiles(sfRenderWindow*, int, tile**)'
         draw_tiles(window, SIZE, tiles);
                                       ^
F:\C\Knight's Tour\MAIN.C:98:30: error: cannot convert 'tile (*)[8]' to 'tile**' for argument '2' to 'void destroy_tiles(int, tile**)'
     destroy_tiles(SIZE, tiles);
                              ^
Process terminated with status 1 (0 minute(s), 0 second(s))
 
Process terminated with status 0 (0 minute(s), 0 second(s))
4 error(s), 5 warning(s) (0 minute(s), 0 second(s))

Thanks for answer, and hope I provided the corect log.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Code::Blocks forces C++ compiler
« Reply #3 on: May 27, 2019, 05:38:29 pm »
Code
F:\C\Knight's Tour\MAIN.C

The uppercase C means C++ to some compilers.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1563
Re: Code::Blocks forces C++ compiler
« Reply #4 on: May 27, 2019, 05:55:07 pm »
Stahta01 is right, and GCC is one of them:

http://labor-liber.org/en/gnu-linux/development/index.php?diapo=extensions

BTW, you have -std=c99 and the include path (..\..\CSFML 2.5\include) duplicated in the project.

Offline Casto_Dailla

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code::Blocks forces C++ compiler
« Reply #5 on: May 27, 2019, 06:31:43 pm »
Thank You very much guys, it solved the problem. Apologies for bothering ye.