Trying to debug some linker errors, I turned on /VERBOSE and I'm trying to make sense of the output. It occurs to me that I really don't know how to read it.
For example:
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 " (??BBox2d@Geometry@VisionMap@@QBE?AVBox2DInt@12@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
What's going on here?
I think I understand this bit:
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 " (??BBox2d@Geometry@VisionMap@@QBE?AVBox2DInt@12@XZ)
1> Referenced in FocusDlg.obj
1> Loaded geometry.lib(Box2d.obj)
It's trying to find the implementation of the above operator, which is used somewhere in FocusDlg.cpp, and it finds it in geometry.lib.
But what does 1>Processed /DEFAULTLIB:libgslcblasMD.lib
mean? What determines the order of symbol resolution? Why is it loading this particular symbol while processing libgslcblasMD.lib
which is a 3rd party library? Or am I reading it wrong?
It seems that the linker is going through the symbols referenced in the project's various object files, but I have no idea in what order. It then searches the static libraries the project uses - by project reference, explicit import and automatic default library imports; but it does so in an order that, again, seems arbitrary to me.
When it finds a symbol, for example in geometry.lib, it then continues to find a bunch of other symbols from the same 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 " (??BBox2d@Geometry@VisionMap@@QBE?AVBox2DInt@12@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)" (??0Box2DInt@Geometry@VisionMap@@QAE@HHHH@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)" (??1Point3d@Geometry@VisionMap@@UAE@XZ)
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)" (??$serialize@Vbinary_oarchive@archive@boost@@@Geometry@VisionMap@@YAXAAVbinary_oarchive@archive@boost@@AAVPoint3d@01@I@Z)
1> Referenced in GPSFrm.obj
1> Referenced in MainFrm.obj
1> Loaded geometry.lib(GeometrySerializationImpl.obj)
But then, for some reason, it goes on to find symbols that are defined in other libs, and returns to geometry later on (a bunch of times).
So clearly it's not doing "look in geometry and load every symbol that's references in the project, and then continue to other libraries". But it's not clear to me what is the order of symbol lookup.
And what's the deal with all those libraries being processed at the beginning of the linker's work, but not finding any symbols to load from them? Does this project really not use anything from msvcrt.lib
, kernel32.lib
? Seems unlikely.
So basically I'm looking to decipher the underlying order in the linker's operation.