Re: [問題] 如何用VC6連結VS2005的lib
※ 引述《WSzc (WSzc)》之銘言:
: 大家好
: 因為需要與其他程式整合的關係
: 我需要用VC6連結一個open source的libs
: 這些libs是VS2005的project所產生 (含source code 我有自行重新build產生)
: 我google查了很久
: 但目前build還是會有很多warning跟1個error:
: error LINK2001: unresolved external symbol _imp__iob_func
: lib確定可以用 因為我用VS2005的project去call他 一切正常
: 但用一模一樣的code的VC6 project就會link error
: 在link上的設定 我都盡量跟VS2005一樣 有些VC6沒有的我就沒辦法改
: 這個error看起來很像是run-time library:/MD /MT沒有設對
: 但我檢查 VC6跟VS2005都是設 /MDd
: 不知為何 請問有人知道可能是什麼問題嗎? 謝謝
我沒有足夠的環境重現、除錯你的問題,但以下是我的推論。
假設有原始碼 vc10.c 且其內容如下:
#include <stdio.h>
int main() {
FILE *fp = __iob_func();
printf("%p\n", fp);
return 0;
}
我使用 Visual Studio 2010 命令提示字元 (32位元) 處理
cl /MDd vc10.c
得到 vc10.exe 與 vc10.obj,執行該程式,可正常運作:
D:\Desktop>vc10.exe
672CF498
此時我們檢驗 vc10.obj 的符號表:
D:\Desktop>dumpbin /all vc10.obj > 11.txt
在 11.txt 中搜尋 __iob_func 可以找到以下內容:
COFF SYMBOL TABLE
000 00AA9D1B ABS notype Static | @comp.id
001 00000001 ABS notype Static | @feat.00
002 00000000 SECT1 notype Static | .drectve
Section length 30, #relocs 0, #linenums 0, checksum 0
004 00000000 SECT2 notype Static | .debug$S
Section length 64, #relocs 0, #linenums 0, checksum 0
006 00000000 SECT3 notype Static | .data
Section length 4, #relocs 0, #linenums 0, checksum 39F2DFD6
008 00000000 SECT3 notype Static | $SG2747
009 00000000 SECT4 notype Static | .text
Section length 25, #relocs 3, #linenums 0, checksum E184D9FF
00B 00000000 SECT4 notype () External | _main
00C 00000000 UNDEF notype External | __imp__printf
00D 00000000 UNDEF notype External | __imp____iob_func
由此可以推論,對於 VC2010 編譯器來說,要 implicit link
這 __iof_func 與 printf 都必須將函數名稱先修飾加上 __imp__ 這 prefix。
顯然這與 原PO 所指出的 _imp 前綴詞相異。
所以,若用 VC6 連結器,或許可以找到 _imp__iob_func 符號,
反之,若用 VC2010 連節器,則只能找到 __imp____iob_func 符號。
讓我們繼續看下去...
同樣打開命令提示字元,準備觀察連結過程,執行
cl /MDd vc10.c /link /verbose > 22.txt
打開 22.txt 還是搜尋 iob_func 可以找到以下內容:
vc10.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:vc10.exe
/verbose
vc10.obj
正在開始第一次階段
已處理 /DEFAULTLIB:MSVCRTD
已處理 /DEFAULTLIB:OLDNAMES
正在搜尋程式庫
正在搜尋 MSVCRTD.lib:
找到 __imp__printf
已在 vc10.obj 中參考
已載入 MSVCRTD.lib(MSVCR100D.dll)
找到 __imp____iob_func
已在 vc10.obj 中參考
已載入 MSVCRTD.lib(MSVCR100D.dll)
所以在 VC2010 環境下,其 MSVCRTD.lib 檔案可以找到原 PO 缺少的符號。
同樣檢驗該檔案的符號表:
dumpbin /all msvcrtd.lib > 33.txt
可以發現以下內容:
Search "iob_func" (7 hits in 1 files)
D:\Desktop\33.txt (7 hits)
Line 782: 42584 ___iob_func
Line 783: 42584 __imp____iob_func
Line 6407: 185 ___iob_func
Line 7202: 185 __imp____iob_func
Line 17264: Symbol name : ___iob_func
Line 17268: Name : __iob_func
Line 126344: ___iob_func
反正結論就是不會有原PO需要的 _imp__iob_func 符號就對了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.8.128.194
推
08/09 18:45, , 1F
08/09 18:45, 1F
→
08/09 18:46, , 2F
08/09 18:46, 2F
→
08/09 18:47, , 3F
08/09 18:47, 3F
→
08/09 18:47, , 4F
08/09 18:47, 4F
推
08/09 19:48, , 5F
08/09 19:48, 5F
→
08/09 19:49, , 6F
08/09 19:49, 6F
→
08/09 19:50, , 7F
08/09 19:50, 7F
→
08/09 19:51, , 8F
08/09 19:51, 8F
→
08/09 19:52, , 9F
08/09 19:52, 9F
→
08/09 19:53, , 10F
08/09 19:53, 10F
→
08/09 19:54, , 11F
08/09 19:54, 11F
→
08/09 19:55, , 12F
08/09 19:55, 12F
→
08/09 19:56, , 13F
08/09 19:56, 13F
→
08/09 21:37, , 14F
08/09 21:37, 14F
→
08/09 21:37, , 15F
08/09 21:37, 15F
推
08/09 21:46, , 16F
08/09 21:46, 16F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):