Linking dll/lib to a cmake project

此生再无相见时 提交于 2020-06-27 08:42:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!