C ++ command line compilation using gcc

I am trying to use a text editor instead of code :: blocks to write C ++ code. Just wrote a hello world program.

My :: blocks ide code uses the gcc compiler I installed, but I want to learn how to do this at a slightly lower level. I read several manuals that say that all I need to do is open a command prompt and enter:

gcc helloWorld.cpp -o helloWOrld 

but I get the error message "gcc" is not recognized.

What am I doing to make it work?

+4
source share
4 answers

If you can compile with the code: blocks, then perhaps it comes with a compiler.

You need to find the path to the compiler (perhaps somewhere in C: \ Program Files \ CodeBlocks ...) The file name is similar to mingw-gcc.exe or mingw-g ++. Exe I also believe that this path can be found in the IDE settings.

When you know the path and file name, just add the path to the PATH system variable and call gccfilename.exe

to compile C ++ programs g ++ filename.exe

You can also run a simple compilation without changing PATH: just run "c: \ Full path to the compiler \ compiler.exe"

+3
source

Do g++ -Wall helloWorld.cpp -o helloWOrld ... for your example

+4
source
0
source

FWIW, gcc is not included in Windows by default. You must install it through MinGW, Cygwin or other means.

You can play with MinGW if you want, but I prefer the gcc compiler with Cygwin ... it's easier for my simple mind to install. Just install Cygwin and be sure to install gcc (this is in the Devel section).

Good luck.

0
source

All Articles