我希望CMake在同一个文件夹中找到三个静态库。这是我的CMakeLists.txt的一部分,我正在努力:
# Dependencies' directories
set(OGRE3D_DIR "D:/Data/Libs/ogre3D-1.10")
# Required libraries
find_library(OGREMAIN_LIB
NAMES OgreMain OgreMain_d
HINTS "${OGRE3D_DIR}/lib/${CMAKE_BUILD_TYPE}")
find_library(OGREOVERLAY_LIB
NAMES OgreOverlay OgreOverlay_d
HINTS "${OGRE3D_DIR}/lib/${CMAKE_BUILD_TYPE}")
find_library(OIS_LIB
NAMES OIS OIS_d
HINTS "${OGRE3D_DIR}/lib/${CMAKE_BUILD_TYPE}")
# Target
add_executable(Test Main.cpp)
# Library linking
target_link_libraries(Test
${OGREMAIN_LIB}
${OGREOVERLAY_LIB}
${OIS_LIB})
出于某种原因,三个变量OGREMAIN_LIB
,OGREOVERLAY_LIB
和OIS_LIB
都设置为NOTFOUND,但如果我尝试打印它们,我发现它们已设置为预期路径(即使是后缀和非后缀名称之间的正确路径也被选中)。显然,所有库都在预期的路径中。
我在这里做错了什么?
答案 0 :(得分:0)
我无法重现你的问题。 find_library()
调用确实正确缓存了调查结果。
以你的例子并添加一些空的占位符来运行测试,我认为它的工作正常:
cmake_minimum_required(VERSION 2.6)
# Dependencies' directories
set(OGRE3D_DIR "ogre3D-1.10")
set(OGRE3D_LIB_DIR "${OGRE3D_DIR}/lib/${CMAKE_BUILD_TYPE}")
file(WRITE "${OGRE3D_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}OgreMain${CMAKE_STATIC_LIBRARY_SUFFIX}" "")
file(WRITE "${OGRE3D_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}OgreOverlay${CMAKE_STATIC_LIBRARY_SUFFIX}" "")
file(WRITE "${OGRE3D_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}OIS${CMAKE_STATIC_LIBRARY_SUFFIX}" "")
# Required libraries
find_library(OGREMAIN_LIB
NAMES OgreMain OgreMain_d
HINTS "${OGRE3D_LIB_DIR}")
find_library(OGREOVERLAY_LIB
NAMES OgreOverlay OgreOverlay_d
HINTS "${OGRE3D_LIB_DIR}")
find_library(OIS_LIB
NAMES OIS OIS_d
HINTS "${OGRE3D_LIB_DIR}")
foreach(_var IN ITEMS OGREMAIN_LIB OGREOVERLAY_LIB OIS_LIB)
get_property(_var_cached CACHE ${_var} PROPERTY VALUE)
message(STATUS "CACHED path: ${_var_cached}")
message(STATUS "path: ${${_var}}")
endforeach()
# Target
file(WRITE main.cpp "int main() { return 0; }")
add_executable(Test Main.cpp)
# Library linking
target_link_libraries(Test
${OGREMAIN_LIB}
${OGREOVERLAY_LIB}
${OIS_LIB})
你可以尝试一下我的最小例子吗?我认为你的问题必须对你的环境做些什么。
答案 1 :(得分:0)
像这样添加$ {CMAKE_SHARED_LIBRARY_PREFIX}和$ {CMAKE_SHARED_LIBRARY_SUFFIX}怎么样?
find_library(OGREMAIN_LIB
NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}OgreMain${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_SHARED_LIBRARY_PREFIX}OgreMain_d${CMAKE_SHARED_LIBRARY_SUFFIX}
HINTS "${OGRE3D_LIB_DIR}")