2010-05-17 28 views
8

試圖調試一些鏈接器錯誤,我打開/ VERBOSE,我試圖弄清楚輸出。我發現我真的不知道如何閱讀它。如何閱讀詳細的VC++鏈接器輸出

例如:

1>Compiling version info 
1>Linking... 
1>Starting pass 1 
1>Processed /DEFAULTLIB:mfc80.lib 
1>Processed /DEFAULTLIB:mfcs80.lib 
1>Processed /DEFAULTLIB:msvcrt.lib 
1>Processed /DEFAULTLIB:kernel32.lib 
1>Processed /DEFAULTLIB:user32.lib 
.... 
1>Processed /DEFAULTLIB:libgslcblasMD.lib 
1>Searching libraries 
1> Searching V:\Src\Solutions\\..\..\\Common\Win32\Lib\PlxApi.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\camerageometry.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\geometry.lib: 
1>  Found "public: __thiscall VisionMap::Geometry::Box2d::operator class VisionMap::Geometry::Box2DInt(void)const " ([email protected]@[email protected]@[email protected]@XZ) 
1>  Referenced in FocusDlg.obj 
1>  Loaded geometry.lib(Box2d.obj) 
1>Processed /DEFAULTLIB:CGAL-vc80-mt.lib 
1>Processed /DEFAULTLIB:boost_thread-vc80-mt-1_33_1.lib 

這是怎麼回事嗎?

我想我明白這一點:

1>Processed /DEFAULTLIB:libgslcblasMD.lib 
1>Searching libraries 
1> Searching V:\Src\Solutions\\..\..\\Common\Win32\Lib\PlxApi.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\camerageometry.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\geometry.lib: 
1>  Found "public: __thiscall VisionMap::Geometry::Box2d::operator class VisionMap::Geometry::Box2DInt(void)const " ([email protected]@[email protected]@[email protected]@XZ) 
1>  Referenced in FocusDlg.obj 
1>  Loaded geometry.lib(Box2d.obj) 

它試圖找到上述操作,這是什麼地方使用FocusDlg.cpp的實施,並發現它在geometry.lib。

但是1>Processed /DEFAULTLIB:libgslcblasMD.lib是什麼意思?什麼決定了符號解析的順序?爲什麼在處理libgslcblasMD.lib這是第三方庫時加載這個特殊符號?還是我讀錯了?

似乎鏈接器正在瀏覽項目各種對象文件中引用的符號,但我不知道按什麼順序。然後它搜索項目使用的靜態庫 - 通過項目引用,顯式導入和自動默認庫導入;但它是按照這樣的順序進行的,這對我來說似乎是任意的。

當它找到一個符號,例如在geometry.lib後,它將繼續以找到相同的lib一堆其他的符號:

1> Searching V:\Src\Solutions\\..\..\\Common\Win32\Lib\PlxApi.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\camerageometry.lib: 
1> Searching ..\..\..\..\out\win32\release\lib\geometry.lib: 
1>  Found "public: __thiscall VisionMap::Geometry::Box2d::operator class VisionMap::Geometry::Box2DInt(void)const " ([email protected]@[email protected]@[email protected]@XZ) 
1>  Referenced in FocusDlg.obj 
1>  Loaded geometry.lib(Box2d.obj) 
1>Processed /DEFAULTLIB:CGAL-vc80-mt.lib 
1>Processed /DEFAULTLIB:boost_thread-vc80-mt-1_33_1.lib 
1>  Found "public: __thiscall VisionMap::Geometry::Box2DInt::Box2DInt(int,int,int,int)" ([email protected]@[email protected]@[email protected]@Z) 
1>  Referenced in FocusDlg.obj 
1>  Referenced in ImageView.obj 
1>  Referenced in geometry.lib(Box2d.obj) 
1>  Loaded geometry.lib(Box2DInt.obj) 
1>  Found "public: virtual __thiscall VisionMap::Geometry::Point3d::~Point3d(void)" ([email protected]@[email protected]@[email protected]) 
1>  Referenced in GPSFrm.obj 
1>  Referenced in MainFrm.obj 
1>  Loaded geometry.lib(Point3d.obj) 
1>  Found "void __cdecl VisionMap::Geometry::serialize<class boost::archive::binary_oarchive>(class boost::archive::binary_oarchive &,class VisionMap::Geometry::Point3d &,unsigned int)" ([email protected][email protected]@[email protected]@@[email protected]@@[email protected]@[email protected]@[email protected]@[email protected]) 
1>  Referenced in GPSFrm.obj 
1>  Referenced in MainFrm.obj 
1>  Loaded geometry.lib(GeometrySerializationImpl.obj) 

但後來,由於某種原因,進而以找到在其他庫中定義的符號,並稍後返回幾何圖形(一堆)。

很顯然,它不是在做「查看幾何圖形並加載項目中引用的每個符號,然後繼續到其他庫」。但是我不清楚是什麼符號查找的順序。

在鏈接器工作開始時處理所有這些庫的處理是什麼,但沒有找到從它們加載的任何符號?這個項目是否真的不使用msvcrt.libkernel32.lib?似乎不太可能。

所以基本上我正在尋找破譯鏈接器操作中的基礎順序。

回答

5

搜索鏈接符號開始於您的應用程序入口點(main或WinMain)。從那裏鏈接器獲取入口點所依賴的所有符號,加載它們自己的依賴關係等等,直到沒有依賴關係。

在較老的鏈接器中,主項目中包含的任何.obj都必須鏈接,因此它們的依賴項應顯示在項目中以使鏈接成功。今天,大多數鏈接器都會刪除從未使用的代碼,即使它包含在明確鏈接的obj文件中。

關於1>Processed /DEFAULTLIB:libgslcblasMD.lib:這只是表示掃描了庫文件,並將其符號附加到字典中,以便稍後將其用於依賴關係解析。

解析發生的順序與處理庫文件的順序不一定有任何關係。當鏈接器處理一個庫時,它只是將它的符號添加到字典中。正如我在上面提到的那樣,從主入口點開始填充字典之後,將創建依賴關係解析。