Single Source File to Executable
$ g++ helloworld.cpp [-o helloworld]
用gcc编译c++:
$ gcc helloworld.cpp -lstdc++ -o helloworld
_____________________________________________
Multiple Source Files to Executable
$ g++ hellospeak.cpp speak.cpp -o hellospeak
_____________________________________________
Source File to Object File
$ g++ -c hellospeak.cpp -o hspk1.o
$ g++ -c speak.cpp -o hspk2.o
$ g++ hspk1.o hspk2.o -o hellospeak
-c:生成.o文件
____________________________________________
Preprocessing
$ g++ -E helloworld.cpp [-o helloworld.ii]
-E:只生成预处理文件
____________________________________________
Generating Assembly Language
$ g++ -S helloworld.cpp
-S:只生成汇编文件
____________________________________________
Creating a Static Library
生成.o文件,ar成一个文件
$ g++ -c sayhello.cpp
$ g++ -c say.cpp
$ ar -r libsay.a sayhello.o say.o
使用静态库
$ g++ saymain.cpp libsay.a -o saymain
_____________________________________________
Creating a Shared Library
生成.o文件,生成.so文件
$ g++ -c -fpic average.cpp
$ gcc -shared average.o -o average.so
或者:
$ g++ -fpic -shared average.cpp -o average.so
_______________________________________________
Libraries
标准C++库为libstdc++.a,它包含了所有的标准C++程序