2
votes

I've just started using C and downloaded CodeBlocks gcc compiler. Now everything has been working fine, i.e. I could create simple source code and compile the .c file from either the command line or through CodeBlocks until just recently.

I had a simple program called fairwell.c, compiled to fairwell.exe via the command line by typing

gcc fairwell.c -o fairwell.exe

which displayed the following text:

Goodbye cruel world

I then deleted these fairwell.c and .exe files. Now everytime I try to compile a new .c file at the command line it keeps displaying this text Goodbye cruel world and does not compile the file. I can, however, still compile files directly through CodeBlocks.

Where is the problem?

1
what command are you using to compile the code ? - TerryG
And on which operating system are you coding? How do you run your file? I would suggest compiling with gcc -Wall -g fairwell.c -o fairwell.exe and running with ./fairwell.exe; use the debugger (e.g. gdb) to find bugs. - Basile Starynkevitch
@hyde: Try type -a gcc or which gcc. The only where command I'm aware of is built into tcsh. - Keith Thompson
Yes that's what I did (thanks hyde), I changed the name of the farewell file to gcc. Its working now - headhog

1 Answers

2
votes

Now everytime I try to compile a new .c file at the command line it keeps displaying this text Goodbye cruel world and does not compile the file.

Well, that means that when you run gcc, you actually run your old farewell program. So, you must have renamed it to gcc somehow, and it is in PATH before real gcc, or most likely in the current directory. If it works under your IDE, it means you should still have the original gcc too, so you shouldn't need to reinstall, at least.

Assuming you are operating under cmd.exe as indicated by the tag, then in the prompt where building fails, give this command:

where gcc

It should print a full path to whatever is run by that command. So examine that file (like, run it with the full path) to verify it is indeed your farewell program, then (just in case) rename it. Building should now work also from command prompt as well as from the IDE, and you can delete the renamed file.

PS. if you are actually using bash instead of cmd.exe, then try which gcc instead to find the wrong gcc.