[問題] 使用3rd lib遇到link error

看板C_and_CPP作者 (Ar藤)時間12年前 (2012/02/19 11:05), 編輯推噓2(206)
留言8則, 3人參與, 最新討論串1/1
sorry 我 po 完文就試出來了 加上 #ifdef _DEBUG #pragma comment(lib, "SoundTouchD.lib") #else #pragma comment(lib, "SoundTouch.lib") #endif 成功 這是論壇查到的 不過還有個問題,因為我lib是用VC build出來的, 如果我使用此lib的程式想用gcc來build, 要怎麼解決name mangling的問題呢??(此lib是c++寫的,非c) 沒什麼用3rd lib的經驗... 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 2010 Express 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) SoundTouch http://www.surina.net/soundtouch/ 問題(Question): 無法link http://www.codeguru.com/forum/archive/index.php/t-517257.html 我遇到的問題跟上面這個人遇到的類似 用2010 VC Express可以成功build出 .lib 檔,但link有問題 我還有用dumpbin去看.lib檔, 其中 455 public symbols 中確實有 19EC2 ??0SoundTouch@soundtouch@@QAE@XZ 19EC2 ??1SoundTouch@soundtouch@@UAE@XZ 而且我也有把 lib 所在目錄加進 project 的 Additional Library Directories 請問要怎麼追查 link 失敗的原因呢? 錯誤結果(Wrong Output): 1>------ Build started: Project: test, Configuration: Debug Win32 ------ 1>test.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall soundtouch::SoundTouch::~SoundTouch(void)" (??1SoundTouch@soundtouch@@UAE@XZ) referenced in function _main 1>test.obj : error LNK2019: unresolved external symbol "public: __thiscall soundtouch::SoundTouch::SoundTouch(void)" (??0SoundTouch@soundtouch@@QAE@XZ) referenced in function _main 1>C:\LetsKTV\SoundTouch_VC_Test\test\Debug\test.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 程式碼(Code):(請善用置底文網頁, 記得排版) #include "SoundTouch.h" #include <iostream> using namespace soundtouch; using namespace std; int main() { SoundTouch m_SoundTouch; cout << "test" << endl; return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.140.149 ※ 編輯: Arton0306 來自: 220.135.140.149 (02/19 11:11) ※ 編輯: Arton0306 來自: 220.135.140.149 (02/19 11:13) ※ 編輯: Arton0306 來自: 220.135.140.149 (02/19 11:16) ※ 編輯: Arton0306 來自: 220.135.140.149 (02/19 13:17)

02/19 13:22, , 1F
name mangling無解,而且還有比這更可怕的地方
02/19 13:22, 1F

02/19 13:22, , 2F
所以改用gcc的話你的lib也要重編
02/19 13:22, 2F

02/19 13:27, , 3F
感謝 只好再研究怎麼用gcc來build了
02/19 13:27, 3F

02/20 19:39, , 4F
我有試過直接改 pe(.coff),小的函式庫還算容易 X D
02/20 19:39, 4F

02/20 19:40, , 5F
.elf 應該更輕鬆一點,畢竟工具更完整
02/20 19:40, 5F

02/20 20:23, , 6F
不只是這個問題,C++ 並未規定如何實作 polymophism
02/20 20:23, 6F

02/20 20:24, , 7F
所以不同的 compiler 會設計不同的 vtable
02/20 20:24, 7F

02/20 20:24, , 8F
member function pointer也是一例,各家實作幾乎都不同
02/20 20:24, 8F
文章代碼(AID): #1FG6RTsj (C_and_CPP)