2010-05-17 61 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:这只是表示扫描了库文件,并将其符号附加到字典中,以便稍后将其用于依赖关系解析。

解析发生的顺序与处理库文件的顺序不一定有任何关系。当链接器处理一个库时,它只是将它的符号添加到字典中。正如我在上面提到的那样,从主入口点开始填充字典之后,将创建依赖关系解析。