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

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?)

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.

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.

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.

Related

How to set up OpenMP?

I am using Codeblocks and have to run an OpenMP C program. So, I added the flag -fopenmp in Codeblocks (compiler settings) and am now getting the error of 'mingw32-g++.exe: error: libgomp.spec: No such file or directory'
So after a bit of searching on the internet about the error, I downloaded TDM-GCC ( installed in C:\TDM-GCC-64). But still the same error is being shown on Codeblocks.
What am I doing wrong?
Here is the build log:
mingw32-gcc.exe -c "D:\Language Files\MatrixMultiplication.c" -o "D:\Language Files\MatrixMultiplication.o"
mingw32-g++.exe -o "D:\Language Files\MatrixMultiplication.exe" "D:\Language Files\MatrixMultiplication.o" -fopenmp
mingw32-g++.exe: error: libgomp.spec: No such file or directory
There are multiple possible causes for this: Either you did not install OpenMP with the compiler or you made a mistake in the Code::Blocks configuration. Anyways go through the following steps and you should be able to fix it. You seem to be working on Windows but I also added remarks on how to do it on Linux.
1) You will need a compiler that comes with OpenMP. For Windows download TDM-GCC preferably the 64-bit executable (second file) and install it. Make sure you select OpenMP in the component tab: Components > gcc (TDM current: ....) > OpenMP (the last entry). Linux already comes with GCC so just open the command line and get yourself OpenMP by typing sudo apt-get install libomp-dev in the terminal.
2) You will have to configure the Compiler in Code::Blocks now: Go to Settings > Compiler under Selected Compiler select GNU GCC Compiler and click Copy and type in a convenient name for your new compiler such as TDM-GCC Compiler. Go to Toolchain executables and browse the directory for all the Program files (C compiler, C++ compiler, Linkers, Debugger, Resource compiler, Make) you should be able to find them in C:\TDM-GCC-64\ ...\bin on a Windows machine if you chose the default installation. I can't tell you the precise sub-directory as I working on a Linux machine but you should be able to find it pretty easily. Depending on your installation there might be two folders for 32- and 64-bit. For Linux this step is not necessary.
4) Then you need to set the Linker settings. This can be done for all projects (which I would not recommend) by doing the following steps in the aforementioned menu or for your current project by clicking Project > Build options. Go to Linker settings of the corresponding configuration (Debug or Release) and click Add under Link libraries. On a Windows machine you will need to browse a file called libgomp-1.dll (32-bit) or libgomp_64-1.dll (64-bit) which should be located in the same folder as the aforementioned Program files. Under Linux instead choose -lgomp under Other linker options.
3) Set the compiler flag -fopenmp (for all the projects or only the current one) by going to Compiler settings > Other compiler options and typing in there -fopenmp.
4) Test it with a program like the OpenMP "Hello World".

Eclipse CDT build C project with gcc not g++

I installed the Mingw32 base to get access to the gcc command (Added also /bin folder to PATH).
Moreover I installed Eclipse CDT Mars, created a C project and selected the MingW32 toolchain.
Now if I try to compile a simple program written in main.c, Eclipse tells me it couldn't find g++.
I know Eclipse can't find g++ because I only installed the MingW32 base, so gcc is the only one available.
But I also created only a C project not a C++ project.
So why eclipse try to compile with g++ not gcc?
How I can change this?

Compile a C program gives "can't find compiler executable in your search path (GNU GCC compiler)" in Codeblocks

I have installed codeblocks in windows 7 first time and try to run a simple C program but I get this error?
can't find compiler executable in your search path (GNU GCC compiler)
I tried many things to solve it but unable to compile.
Have you installed the Mingw compiler or any other simiar compiler? If not install that first. After you have done so, you need to set codeblocks to use that compiler. You can do that by going to the settings>compiler settings and set the necessary options there. You may need to refer the place where you have installed Mingw or other compiler. Note the compiler executable is gcc for C and g++ for C++ and the linker is ld i guess. Debugger is gdb. You need to tell codeblocks where are these located.
I also received that error. I fixed it using Settings -> Compiler -> Global compiler settings -> Toolchain executables -> Auto detect.

compiling Vim 7.4 under AIX 6.1

I have a problem while compiling Vim 7.4 under AIX 6.1.
My options for the configure script are: "--prefix /opt/freeware/bin" and "--enable-pythoninterp".
There where no Errors while running the configure Script but when I try to run "make" I get the error message:
cd src && make first
cc -qlanglvl=extc89 -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA -DFUNCPROTO=15 -g -o objects/regexp.o regexp.c "regexp_nfa.c"
line 4410.1: 1506-046 (S) Syntax error.
make: 1254-004 > The error code from the last command is
1.
Stop. make: 1254-004 The error code from the last command is 2.
Stop.
Does anyone know what to do?
I had compiled Vim 7.4 in my home directory so I know that there is a workaround but I can't find it anymore.
AIX's built in make (based on standard AT&T make) is not compatible with the Makefiles built by autoconf tools. Use GNU make (gmake) instead. You may already have it installed (check /opt/freeware/bin), install from the Linux Toolbox for AIX set (from IBM), or from one of the websites providing prebuilt GNU tools for AIX systems (perzl, bullfreeware, etc). Just provide an alias from make to gmake, or override the use of make in the Makefile itself.

Eclipse doesn't compile *.C with gcc

I am using Eclipse Kepler and running it under Win7 64-Bit. As compiler I use the gcc (4.8.1) from MinGW. Now I have the following problem:
//edit: Reformulated question to make it more clear
I have a project containing of one source-file with C-Code: main.c
This file can be compiled over 2 ways:
Start the compiler over the command-line: gcc -o main.exe main.c
Start the compiler over Eclipse by starting the normal build-routine (which also calls the gcc)
Now for some reason I want to add some C++-Code, but I still want to compile it with the gcc.
The gcc itself decides how to compile over the file extension - This means, if main.c contains C++-Code and I call gcc -o main.exe main.c it won't work. To make the compiler realize it's C++ I have to change the file-extension to somthing like .C or .cpp and then it will work.
Now back to Eclipse:
When I change my Sourcefile to main.C Eclipse interprets it as C++ File, meaning it changes the Code-Highlighting. When I now start a build process over Eclipse it just tells me
Info: Nothing to build for PROJECT
This means there is not even a call to the gcc-compiler. My guess is, that Eclipse somehow doesn't want to call the gcc, because the source-file is marked as C++-File.
//edit2: Just tried - when I have a C++-Projekt Eclipse just ignores the *.C or the *.cpp-files. I guess I have to add them manually, so they're built too ... but where?
The g++ is the compiler to compile C++ codes.
Change you compiler in you eclipse project.

Resources