Eclipse doesn't compile *.C with gcc - c

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.

Related

Using the gcc (GNU C) compiler with C99 under Windows (from CLion)

I am currently programming in the C language on CLion from JetBrains from a Windows computer.
I would like to use the gcc (GNU C) compiler in order to access external libraries, like BLAS.
At this point, in order to launch the hello.c program for instance, I need to go the CMakeLists.txt file and write this:
cmake_minimum_required(VERSION 3.23)
project(ProjectName C)
set(CMAKE_C_STANDARD 99)
add_executable(ProjectName hello.c)
To compile hello.c from gcc, I would need to enter cc hello.c in the gcc terminal. As CLion has no compilation problem using CMakeLists.txt, so far, so good.
Now, I want to use the dgemv_ function for matrix multiplication. I got the dgmev.f Fortran file. To execute my program, I need to use the BLAS librairy, and write cc hello.c -lblas in gcc. However, I have no idea how to link my Fortran librairy program with my C program without gcc (which I haven't).
Thus, I would like to know how to use the gcc compiler in CLion for C99 under Windows (maybe with a Makefile script ?), or, if it's not possible, how to use this Fortran librairy program without gcc.
Here you have the complete CLion project folder on Google Drive containing all the scripts I wrote about above.

Compiling SDL on Windows with Mingw gcc

I downloaded SDL for MinGW here : https://www.libsdl.org/download-2.0.php.
But when I try to compile with gcc it can't find the libraries.
It says it cannot find "SDL2/SDL.h".
I tried running GCC with the parameters to include the path after moving the folder containing
SDL2 to the same directory of the project.
I used this command:
gcc main.c render.c sprite.c logic.c menu.c level.c -o release -l:SDL2\x86_64-w64-mingw32\lib\libSDL2main.a -l:SDL2\x86_64-w64-mingw32\lib\libSDL2.a -ISDL2
If you want the compiler to find the libraries, you need to include the directory it is in using -I/dir/

Using GCC to compile C code

I installed MinGW on my Windows 8 laptop and tried to compile a C code file with
gcc test.c -o test.exe
the compiler gave no warnings or errors but it did not create test.exe
how do i get the compiler to create the file
test.c
My terminal session
An interesting observation:
When I deliberately introduce an error in the code and try to compile the compiler shows the error
Code with error
Compiler output
When I try compiling the same code using Command Prompt
This is what it shows
But the file does exist in the MinGW\bin directory
I moved the
test.c
file to
C:\
and started the command prompt in the
C:\MinGW\bin
directory
and here is what it outputs
Problem partially solved:
I disabled hybrid boot in windows 8 and restarted the computer. The compiler now works in Command Prompt but not in PowerShell.
Try to compile your code normally as
gcc test.c
If you get default output file a.exe,then go for
gcc test.c -o test.exe
I would suggest you go through this compilation instruction :-
gcc -o test.exe test.c
I believe this code runs perfectly on your windows system.Please inform if it doesn't!
I know this is an old question, but I came across this after having this same issue and managed to solve it.
When I installed MinGW on my computer, I didn't add the MinGW bin directory to my PATH (<mingw install dir>\bin). I had written some code that referred to the GNU compiler binaries by their full path, and when I tried to compile something I experienced the same behavior you described.
So it seems like MinGW won't work properly unless it is added to your PATH. I think it's weird that gcc didn't complain about it though.
One possibility is Microsoft's use of VirtualStore.
This can cause problems with "missing" files with Cygwin. See for example, Cygwin sees a file that windows can't--I want to access this file from python and https://superuser.com/questions/400600/file-only-visible-to-cygwin-not-windows.
To verify whether this is the case, try doing a search of your entire hard drive for the file test.exe. Or try MinGW's ls rather than dir.
And since the OP "partially solved" the problem by moving to another directory, this could be the cause.

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

Can't Link Psapi.h in Open Source Project Using MinGW

I am trying to modify the source code to an open source application on windows that uses mingw.
I am having a problem linking the psapi library.
psapi.h and libpsapi.a are in the mingw directory and I have tested it using the standard
gcc -o program program.c -lpsapi
method, and it works.
However, when I try to compile the program using the
./configure
make
method, it doesn't work I have tried,
./configure LDFLAGS=-lpsapi
make
and that doesn't work
and I tried going into the makefile.am and putting -lpsapi in AM_LDFLAGS but that doesn't work
The error it gives is just a standard "undefined reference to [function]", implying that the library with the functions is not linked
I have even tried putting psapi.h in the source directory and including it as #include "psapi.h" and that STILL didn't work.
LDFLAGS is the wrong one.
LIBS=-lpsapi should do the trick.
The order is important for the linker. The libraries (LIBS) have to come after the objects, LDFLAGS can be before.

Resources