[GCC for C++]編譯選項—IDE掩蓋下的天空
來源:互聯網
上載者:User
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++程式