gpt4 book ai didi

CMake find_library 找不到库

转载 作者:行者123 更新时间:2023-12-01 07:47:15 25 4
gpt4 key购买 nike

我想出了以下 super 简单的 FindMAGMA.cmake 脚本来查找 MAGMA 库,因为周围没有:

# - Find the MAGMA library
#
# Usage:
# find_package(MAGMA [REQUIRED] [QUIET] )
#
# It sets the following variables:
# MAGMA_FOUND ... true if magma is found on the system
# MAGMA_LIBRARY_DIRS ... full path to magma library
# MAGMA_INCLUDE_DIRS ... magma include directory
# MAGMA_LIBRARIES ... magma libraries
#
# The following variables will be checked by the function
# MAGMA_USE_STATIC_LIBS ... if true, only static libraries are found
# MAGMA_ROOT ... if set, the libraries are exclusively searched
# under this path

#If environment variable MAGMA_ROOT is specified, it has same effect as MAGMA_ROOT
if( NOT MAGMA_ROOT AND NOT $ENV{MAGMA_ROOT} STREQUAL "" )
set( MAGMA_ROOT $ENV{MAGMA_ROOT} )
# set library directories
set(MAGMA_LIBRARY_DIRS ${MAGMA_ROOT}/lib)
# set include directories
set(MAGMA_INCLUDE_DIRS ${MAGMA_ROOT}/include)
# set libraries
find_library(
MAGMA_LIBRARIES
NAMES "libmagma"
PATHS ${MAGMA_ROOT}
PATH_SUFFIXES "lib"
NO_DEFAULT_PATH
)
set(MAGMA_FOUND TRUE)
else()
set(MAGMA_FOUND FALSE)
endif()

获取 include 和 lib 路径很简单。但是,除非我包含扩展名,否则它在 Ubuntu 中找不到文件“libmagma.a”或在 Mac OS X 中找不到“libmagma.dylib”文件,但这违背了目的,不是吗?谁能建议我在这里做错了什么?

最佳答案

去掉前导lib从库名

find_library(
MAGMA_LIBRARIES
NAMES magma
PATHS ${MAGMA_ROOT}
PATH_SUFFIXES lib
NO_DEFAULT_PATH
)

另外,看看 FindPackageHandleStandardArgs 这可以帮助您摆脱查找脚本中通常需要的一些样板代码。

关于CMake find_library 找不到库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17747470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com