[問題] inline 和 linking error
開發平台(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
10/10 02:16, 1F
→
10/10 02:17, , 2F
10/10 02:17, 2F
→
10/10 02:18, , 3F
10/10 02:18, 3F
推
10/10 03:07, , 4F
10/10 03:07, 4F