我的博客首頁(點擊查看詳情) -- https://blog.51cto.com/11495268
ios
Linux 環境下的 C++ 開發(本文 不會 過多解釋 基礎語法,主要用於 溫故知新 的目的)
c++
## 安裝 g++ # apt-get install g++ # g++ --version g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# cat my_first_pg_c++.cpp #include <iostream> using namespace std; int main(int argc, char *argv[]) { cout << "I want free" << endl; return 0; }
# g++ my_first_pg_c++.cpp -o my_first_pg_c++ # ./my_first_pg_c++ I want free
通常 C++ 源碼文件 以 ".cpp" 後綴 結尾
ubuntu
預處理 語句 :#include <iostream>
使用命令空間 std :using namespace std;
主函數聲明 :int main(int argc, char *argv[])
標準輸出語句 : cout << "I want free" << endl;
返回語句(結束標誌):return 0;
vim
# vim my_first_pg_c++.cpp
## 預處理 執行預處理語句,生成 編譯文件 gcc -E my_first_pg_c++.cpp -o my_first_pg_c++.i
## 編譯 生成 彙編文件 gcc -S my_first_pg_c++.i -o my_first_pg_c++.s
## 彙編 生成 目標文件,通常以 ".o" 後綴 # gcc -c my_first_pg_c++.s -o my_first_pg_c++.o
## 將目標文件、庫文件 連接成 可執行文件 # gcc -g -v -Wall my_first_pg_c++.o -o my_first_pg_c++