Tuesday, May 8, 2012

C++: First steps on Fedora

Install compiler, autoconf and automake tools:

$ sudo yum install gcc gcc-c++ autoconf automake

autoconf - a tool for producing configure scripts for building, installing and packaging software on computer systems where a Bourne shell is available [1];

automake - a programming tool that produces portable makefiles for use by the make program, used in compiling software [2];

GNU GCC C compiler (gcc)  - the package contains a GNU Compiler Collection;

GNU GCC C++ compiler (gcc-c++) - the package adds C++ support to the GNU Compiler Collection [3].

$ man g++

gcc - GNU project C and C++ compiler
...
When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage.  For example, the -c option says not to run the linker.  Then the output consists of object files output by the assembler.
...

To compile multiple cpp files and link them together use:

$ g++ main.cpp file_1.cpp file_n.cpp

a.out executable file will be generated. Run it as:

$ ./a.out

OR, compile files separately and link generated object files:

$ g++ -c main.cpp
$ g++ -c file_1.cpp
$ g++ -c file_n.cpp
$ g++ -o out.file main.o file_1.o file_n.o

and simply run the generated executable file:

$ ./out.file

Useful links:

Sources:

No comments:

Post a Comment