本篇介紹如何在 linux 環境下編譯多個 CPP 檔

 

檔案:

main.cpp

money.cpp

money.h

如何編譯多個C檔(1).png

事先提醒:

 

#include <money.h>

檔案在不同資料夾

 

#include "money.h"

檔案在同一個資料夾

 

 

 

步驟:

1. 先編譯 money.cpp  (class) :    g++ -c money.cpp

編譯完會產生 money.o

 

2. 再編譯 main.cpp                :     g++ main.cpp -o main -I ../include ../include/money.o

 指令解釋: 利用 g++ 編譯 main.cpp 並將目的檔存為main ,到../include 去找尋 money.o , 並將2者link 起來

PS: -I  (大寫 i)  連結檔的目錄  連結檔的名稱

編譯完會產生 main

 

3. 執行 main                         :  ./main

 

 

步驟示意圖

如何編譯多個C檔(2).png

如何編譯多個C檔(3).png

arrow
arrow
    全站熱搜

    大神(偽) 發表在 痞客邦 留言(0) 人氣()