I have been asked to help a colleague regarding a mysterious build error in one of the projects in a common solution. The build error happens in the linkage stage, a class constructor defined in a static lib (a.lib) is not found when it is used in a lib (b.lib) that includes that a.lib. After careful investigation I figured out that:
vcxproj file ClCompile ItemGroup:
...
<ClCompile Include="Source\CMYKOVBLab.cpp" />
<ClInclude Include="Source\CMYKOBGLab.cpp" /> <--- The file is here.
<ClCompile Include="Source\CMYKOVBRGB.cpp" />
...
In summary, what is needed to link the library is there, but the linkage error persists.
One strange thing I noticed is the fact that the cpp with the class constructor not found could not be compiled by hitting Ctrl-F7 or the right button in a.lib. That option is grayed out, but only for that particular file. Moreover, when I build the a.lib library where this file should be compiled, it is not, and therefore no object file is created.
What can be the cause? How can I fix it?
I am using Visual Studio Professional 2015 Update 3.
In VS 2015 the compile include files defined in the .vcxproj project file are expected to be in lexicographical order.
This is no longer needed in VS 2017 but when it is not respected, VS 2015 can create this kind of chaos.
Your colleague has modified manually the .vcxproj project file to include that file, but he has not respect the lexicographical order. You need simply to remove the file from the project and add it back again. Visual Studio will include it in the right place and your build will succeed.
Hope this can help other people too.