[問題] inline 和 linking error

看板C_and_CPP作者 (拒看低質媒體)時間12年前 (2011/10/09 12:33), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) php extension 問題(Question): inline function 是否會導致 already defined 錯誤結果(Wrong Output): linking error utility::word_to_hex already defined 程式碼(Code):(請善用置底文網頁, 記得排版) 我在寫一個php extension with C++ 我將整個工作拆成兩部分: 先寫一個負責演算法部分的 .lib 然後再寫一個php extension .dll 負責C 和 php之間資料結構的轉換 .lib內我於 utility.h 內寫了以下這個function: namespace utility { const std::string& word_to_hex(const word& src, std::string& dst); inline const std::string word_to_hex(const word& src) { std::string retval; return word_to_hex(src, retval); } } php extension .dll 部分的code我想和這個問題可能無關, 所以就先不po了 補充說明(Supplement): 我查到的資料都是inline function 不會導致 already defined 的問題 inline function的定義必須放在 header file 內否則linking時會有unresolve external btw, 我自己也有寫一個 test.exe 來測試, 同樣的 code 和 linking 都沒有問題 但是我在編譯 .dll 的時候就跳出 linking error 了 請問在編寫.dll時是不是不可以用到inline function呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.137.0.118

10/10 02:16, , 1F
DLL中的inline關鍵字好像會被自動忽略。所以重複引用DLL可
10/10 02:16, 1F

10/10 02:17, , 2F
能會造成已定義
10/10 02:17, 2F

10/10 02:18, , 3F
我猜的XD,以下有請其他神人說明!
10/10 02:18, 3F

10/10 03:07, , 4F
編 dll 的話,的確會被忽略; 編 lib 的話就不會被忽略.
10/10 03:07, 4F
文章代碼(AID): #1EaIG29Z (C_and_CPP)