我的cmake的输出是一个静态库.我正在创建它:
add_library(myMainLib STATIC ${BACKEND_SOURCES})
当我尝试让myMainLib链接到第三方lib / dll时出现问题. dll文件将在运行时找到,但是,我正在尝试导入/链接lib文件,但没有成功.我的第三方库是SDL2和SDL2 NET.
我认为这是直截了当的,并且已经用尽了我在网上找到的所有方法.都失败了.我尝试过的列表如下.请告诉我我做错了什么.
>简单方法,使用target_link_libraries
add_library(myMainLib STATIC ${BACKEND_SOURCES}) target_link_libraries(myMainLib path_to_thirdPartyLib/thirdParty.lib)
>根据cmake docs
add_library(myMainLib STATIC ${BACKEND_SOURCES}) add_library(Third_Party SHARED IMPORTED) set_property(TARGET Third_Party PROPERTY IMPORTED_LOCATION path_to_thirdPartyLib/thirdParty.dll) set_property(TARGET Third_Party PROPERTY IMPORTED_IMPLIB path_to_thirdPartyLib/thirdParty.lib) target_link_libraries(myMainLib Third_Party)
>使用链接目录设置库的路径
add_library(myMainLib STATIC ${BACKEND_SOURCES}) set(LIB_DIR path_to_thirdPartyLib) LINK_DIRECTORIES(${LIB_DIR}) target_link_libraries(myMainLib ${LIB_DIR}/thirdParty.lib)
>尝试查找库
add_library(myMainLib STATIC ${BACKEND_SOURCES}) find_library(Third_Party thirdParty.lib) if(Third_Party) #never gets in here target_link_libraries(myMainLib ${Third_Party}) endif()