Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ command line compilation with gcc

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

My code::blocks ide uses the gcc compiler that I installed, but I want to learn how to do it at a bit of a lower level. I read a few tutorials that said all I have to do is open a command prompt and type:

gcc helloWorld.cpp -o helloWOrld

but i get an error saying "gcc" is not a recognized anything.

What do i do to make it work?

like image 384
Terryl Avatar asked Apr 12 '13 21:04

Terryl


People also ask

Can gcc compile C code?

GCC is a key component of so-called "GNU Toolchain", for developing applications and writing operating systems. The GNU Toolchain includes: GNU Compiler Collection (GCC): a compiler suite that supports many languages, such as C/C++ and Objective-C/C++.

What is the gcc C command?

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++.

Can G ++ compile C code?

gcc is used to compile C program. g++ can compile any . c or . cpp files but they will be treated as C++ files only.


2 Answers

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

like image 88
blackmamba591 Avatar answered Oct 01 '22 08:10

blackmamba591


If you can compile with code:blocks, than probably it ships out with compiler.

You need to find a path to the compiler (probably somewhere in C:\Program Files\CodeBlocks...) The file name is something like mingw-gcc.exe or mingw-g++.exe I believe also, that you can find this path in IDE settings.

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

to compile c++ programms run g++filename.exe

Also you can run simple compilation without modifying PATH: just run "c:\Full path to compiler\compiler.exe"

like image 38
podshumok Avatar answered Oct 01 '22 09:10

podshumok