问题
I was trying to link a library to my cmake project but I was getting linker errors. I spent 2 hours trying to resolve the problem and I created simple project where I hardcoded all the paths.
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(Testing CXX)
INCLUDE_DIRECTORIES("B:/Projects/TMH/Libraries/Awesomium/inc")
SET(SOURCE_FILES
src/Main.cpp
src/Application.cpp
src/Window.cpp
)
ADD_EXECUTABLE(Testing ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(Testing B:/Projects/TMH/Libraries/Awesomium/bin/awesomium.dll)
But even that code fails to compile and throws linker errors like this:
CMakeFiles\Testing.dir/objects.a(Application.cpp.obj): In function `ZN9PXLClient11ApplicationD2Ev':
B:/Projects/TMH/Testing/src/Application.cpp:15: undefined reference to `_imp___ZN9Awesomium7WebCore8ShutdownEv'
CMakeFiles\Testing.dir/objects.a(Application.cpp.obj): In function `ZN9PXLClient11Application3RunEv':
B:/Projects/TMH/Testing/src/Application.cpp:20: undefined reference to `_imp___ZN9Awesomium9WebConfigC1Ev'
I either tried to link the .lib file instead of the .dll one. I changed
TARGET_LINK_LIBRARIES(Testing B:/Projects/TMH/Libraries/Awesomium/bin/awesomium.dll)
to
TARGET_LINK_LIBRARIES(Testing B:/Projects/TMH/Libraries/Awesomium/lib/Awesomium.lib)
But I was getting exactly the same errors. I'm 100% sure that both paths are correct.
How to correctly link a dll/lib to cmake project?
来源:https://stackoverflow.com/questions/40113883/linking-dll-lib-to-a-cmake-project