[問題] 動態連結程式庫實作

看板C_and_CPP作者 (新兵)時間9年前 (2015/06/19 22:15), 9年前編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) gcc, Linux 問題(Question): 在念 程式設計師的自我修養 一書中看到的 在第185頁 簡單說有兩支程式 他們都呼叫一個寫在Lib.h/Lib.c的函式foobar (程式碼在下方) 然後下指令: gcc -fPIC -shared -o Lib.so Lib.c 來產生.so檔案 問題是:為什麼這邊的Lib.c不用include Lib.h??? 程式碼(Code):(請善用置底文網頁, 記得排版) // Lib.c #include <stdio.h> void foobar( int i ) { // Do something; } // Lib.cpp #ifndef LIB_H #define LIB_H void foobar( int i ); #endif -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.225.10.108 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1434723346.A.BB7.html ※ 編輯: peter98 (36.225.10.108), 06/19/2015 22:18:05

06/19 22:21, , 1F
因為沒用到啊。要用到到『現在』還沒有出現的才要宣告
06/19 22:21, 1F

06/19 23:28, , 2F
如果在 foobar 前面插入一個會用到 foobar 的 function
06/19 23:28, 2F

06/19 23:28, , 3F
你就會需要 header
06/19 23:28, 3F

06/20 10:57, , 4F
了解 謝謝!
06/20 10:57, 4F
文章代碼(AID): #1LX2GIkt (C_and_CPP)