Situation
I learned a lot over the last year, but this is something I just could not wrap my head around. Project is C++. CMake 1.15.2. Visual Studio 2015.
I converted a whole Solution *.sln file with cmake-converter and wrote FindXXX.cmake Modules for all external *.libs defined in the *.vcxproj files.
Everytime I encountered an error: unresolved external I added the corresponding Target Sometarget::somecomponent to the target_link_libraries(ConsumingTarget ... ) call.
Now I have a build that works and produces no errors. Some executables say something along the lines of:
"Execution of code cannot be continued because somecomponent.dll is not found..."
I have
- An original
.slnfile that produces executables only requiring.libfiles - A CMake generated
.slnfile that produces executables requiring.dllfiles - Working FindXXX.cmake files which
add_library(XXX::yyy UNKNOWN IMPORTED)- They find the headers and the
.libfiles (.dllfiles are not existing/intended/needed in the original VS.sln) - They create the corresponding Targets for all
.libfiles
- They find the headers and the
- Consuming Targets which
target_link_libraries(ConsumingTarget PRIVATE XXX::yyy) - "A working build"
- An error "before starting the main function".
What I have tried
I have tried defining an OBJECT Library and adding this to the sources of ConsumingTarget and removing Sometarget::somecomponent from the target_link_libraries call. CMake Doc on Object Libraries
I have tried reading and understanding the difference between module and library. Even the CMake documentation on imported Libraries couldn't help me understand my problem.
I have tried reading and understanding the difference between linking a static and shared library.
My Assumptions
- Adding the imported library is done wrong by me.
- Reason: DependenciesGui.exe shows different dependencies for the cmake-generated-executable and the original-sln-executable but the linker calls (shown in VisualStudio 2015) seem to be the same.
- Whole Program Optimization in the CMake File does not work the same way it does in the original .sln file although the Flags are activated at all levels described in this answer.
- Reason: compiling with the original file I noticed
warning C4505: 'foobar': unreferenced local function has been removed- I don't seem to get those warnings with the cmake-generated build. - subassumption: Functions which won't be called are optimized away, thus removing the necessity for the
.dllfile.
- Reason: compiling with the original file I noticed
I expect/hope for
ConsumingTarget.exeto run without asking forsomecomponent.dll- another explanation on imported targets and how to link libraries where
.dlls should not be necessary. - an explanation on how to analyze/compare the two binaries regarding their symbols(?) and map the seen information to CMake commands. (I am using DependenciesGui.exe to look for dependencies in the .exe file)
Possible reason for failure
- One executable had no /DELAYLOAD... directive after conversion with cmake-converter. Opened Issue. Question Title still holds.
Edits: 1: Added possible reason for failure