Compiling C ++ using the gcc / g ++ compiler

I am new to C ++ and I want to compile my test program.
I now have 3 files "main.cpp" "parse.cpp" "parse.h"

how can i compile it with a single command?

+3
source share
4 answers

Compile them both at the same time and put the result in a.out

$ g++ file.cpp other.cpp

Compile them both at the same time and put the results in prog2

$ g++ file.cpp other.cpp -o prog2

Compile each separately and then pair them with a.out

$ g++ -c file.cpp
$ g++ -c other.cpp
$ g++ file.o other.o

Compile each separately and then pair them with prog2

$ g++ -c file.cpp
$ g++ -c other.cpp
$ g++ file.o other.o -o prog2
+22
source

make utility make . .

, gcc ...

.h, .cpp.

gcc a.cpp b.cpp -o program.out
./program.out

+8

, , " ". , , .

, CMake. - , . , , , , AutoTools

: www.cmake.org

+3

, g++, main, :

g++ main.cpp -o main

"". "-o" , . , man- (man g++).

+2

Source: https://habr.com/ru/post/1713045/


All Articles