作者peter98 (新兵)
看板C_and_CPP
標題[問題] 動態連結程式庫實作
時間Fri Jun 19 22:15:43 2015
開發平台(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
→ kerwinhui: 因為沒用到啊。要用到到『現在』還沒有出現的才要宣告 06/19 22:21
→ Bencrie: 如果在 foobar 前面插入一個會用到 foobar 的 function 06/19 23:28
→ Bencrie: 你就會需要 header 06/19 23:28
→ peter98: 了解 謝謝! 06/20 10:57