我试图将库链接到我的cmake项目,但我收到链接器错误。我花了2个小时试图解决问题,我创建了一个简单的项目,我在其中硬编码所有路径。
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)
但即使该代码也无法编译并抛出链接器错误,如下所示:
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'
我或者尝试链接.lib文件而不是.dll文件。我改变了
TARGET_LINK_LIBRARIES(Testing B:/Projects/TMH/Libraries/Awesomium/bin/awesomium.dll)
到
TARGET_LINK_LIBRARIES(Testing B:/Projects/TMH/Libraries/Awesomium/lib/Awesomium.lib)
但我得到了完全相同的错误。我完全确定两条路径都是正确的。
如何正确地将dll / lib链接到cmake项目?