Jayy
Jayy

Reputation: 14728

C Hello world: Code Blocks IDE, MinGW C compiler on windows

I can't get Code Blocks IDE to compile the hello world C program it creates when you create a new C project. I've installed MinGW and it was recognised by the IDE. But when I try to build I get the following output:

-------------- Build: Debug in TestC3 (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -g  -c
C:\Users\jody\codeblocks\testc3\TestC3\main.c -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\TestC3.exe obj\Debug\main.o    Execution
of 'mingw32-g++.exe  -o bin\Debug\TestC3.exe obj\Debug\main.o' in
'C:\Users\jody\codeblocks\testc3\TestC3' failed.

Why is it trying to run mingw32-g++.exe as well as mingw32-gcc.exe? (And if it shouldn't be doing this, how can I configure it not to?)

Upvotes: 5

Views: 52374

Answers (3)

Lalit yadav
Lalit yadav

Reputation: 1

It may occur because compiler installation directory path is wrong.to fix it settings -> compiler -> toolchain executables. now set compiler directory to compiler folder. it must be in CodeBlocks folder if you downloaded CodeBlocks compiler integrated version(ex: C:\Program Files\CodeBlocks\MinGW). else you need browse to location where compiler is installed

if you can't find compiler then uninstall codeblocks and download again . but this time make sure you downloaded one which has "mingw" in name for windows.

Upvotes: 0

Christopher Nolan
Christopher Nolan

Reputation: 1107

Firstly uninstall the codeblocks if you can't get something right. Move to codeblocks official site to download its minw.exe version so that you have a proper compiler for all of your C programs. After installing go to Setting>Compiler>GNU GCC compiler. Move to Toolchain Executables>. Now set Compilers Installation Directory. Most probably it's C:\Program Files\CodeBlocks\MinGW\bin. Now you have to select and locate your C compiler as it is in the above mentioned directory. After that rebulid and run your program.

Upvotes: 3

Mike Kinghan
Mike Kinghan

Reputation: 61307

The mingw32-gcc.exe step is the compile step. The mingw32-g++.exe is the link step. This is the correct sequence and will work if your mingw32 installation is "normal" and correct - where "normal" means you have installed the C++ as well as the C tools.

The link step is failing for you because mingw32-g++.exe cannot be executed, most likely because it does not exist on your PATH. Try running mingw32-g++.exe at the command prompt to check. Look in the directory where mingw32-gcc.exe resides to see if mingw32-g++.exe is also there.

If your mingw32 installation has got broken somehow I suggest you uninstall and reinstall.

If you have intentionally installed only the C tools then that will explain what you are seeing, and it is easily fixed:

Both mingw32-gcc.exe and mingw32-g++.exe are just tool driver programs. When invoked with compilation options for .c files, mingw32-gcc.exe invokes the C compiler. When invoked with compilation options for .cpp|cxx|... files, mingw32-g++.exe invokes the C++ compiler. If either of them is invoked with linkage options then it invokes the linker.

Codeblocks by default configures mingw32-g++.exe to invoke the linker because it will do equally well for C projects, C++ projects and C/C++ projects, and it assumes you have the full C/C++ toolchain.

If you have not installed C++ tools and only want to build C, then you can use mingw32-gcc.exe to invoke both the C compiler and the linker. To configure this in the CodeBlocks IDE:

  • Navigate Settings -> Compiler
  • Ensure that the Selected Compiler is GNU GCC
  • Tab to Toolchain executables
  • Change Linker for dynamic libs from mingw32-g++.exe to mingw32-gcc.exe
  • OK out of Settings and rebuild your project.

Upvotes: 17

Related Questions