We use the -o option to specify the output file name
g++ -o hello hello.cpp
./hello
g++ -Wall -g -o hello hello.cpp
-o
: specifies the output executable filename.-Wall
: prints "all" Warning messages.-g
: generates additional symbolic debuggging information for use with gdb debugger.
Compile-only with -c option g++ -c -Wall -g hello.cpp
Link object file(s) into an executable g++ -g -o hello hello.o
g++ -o myprog file1.cpp file2.cpp
Create the following file named "makefile" (without any file extension), which contains rules to build the executable, and save in the same directory as the source file. Use "tab" to indent the command (NOT spaces).
all: hello
hello: hello.o
gcc -o hello hello.o
hello.o: hello.c
gcc -c hello.c
clean:
rm hello.o hello
or
all: hello
hello: hello.c
gcc -o hello hello.c
clean:
rm hello
all: myprog
myprog: myprog.c
gcc -o myprog file1.cpp file2.cpp
clean:
rm myprog