在CMake项目中使用vendored OpenBLAS作为依赖项



我已经在thirdparty/OpenBLAS中将OpenBLAS作为Git子模块签出。带

add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/OpenBLAS")

在CCD_ 2中,它成功地进行了配置和构建。但是

target_link_libraries(encoder_sample fused_transformer OpenBLAS::OpenBLAS OpenMP::OpenMP_CXX ${CMAKE_THREAD_LIBS_INIT})

未能找到目标:

Target "encoder_sample" links to target "OpenBLAS::OpenBLAS" but the target
was not found.  Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?

如果重要的话,我将使用带有WSL的Visual Studio 2019。我以为我错过了一些琐碎的事情,只是想不出是什么。。。

因为您将配置和构建OpenBLAS作为CMake项目的一部分,所以IMPORTED目标OpenBLAS::OpenBLAS不可用。在机器上安装OpenBLAS后,导入的目标由OpenBLASConfig.cmake配置文件定义,通常与find_package(OpenBLAS ...)命令一起使用。在您的情况下,您可以直接使用OpenBLAS CMake目标,定义它们的CMake文件。

假设你的OpenBLAS存储库与这个GitHub repo类似,CMake目标在这里定义:

set(OpenBLAS_LIBNAME openblas${SUFFIX64_UNDERSCORE})
...
add_library(${OpenBLAS_LIBNAME} ${LA_SOURCES} ${LAPACKE_SOURCES} ${RELA_SOURCES} ${TARGET_OBJS} ${OpenBLAS_DEF_FILE})

因此,根据您的目标体系结构,您要使用的目标名称将是openblasopenblas_64。因此,对于64位构建,您可以尝试以下操作:

target_link_libraries(encoder_sample fused_transformer openblas_64 OpenMP::OpenMP_CXX ${CMAKE_THREAD_LIBS_INIT})

最新更新