我使用的是cmake 3.16,我知道cmake支持使用FindBLAS (here)查找OpenBLAS。
我正在尝试将OpenBLAS链接到我的c++项目。这是我的CMakeLists.txt。
cmake_minimum_required(VERSION 3.15)
project(my_project)
# source file
file(GLOB SOURCES "src/*.cpp")
# executable file
add_executable(main.exe ${SOURCES})
# link openblas
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(${BLAS_INCLUDE_DIRS})
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)如果我运行cmake,它会运行just find,并输出OpenBLAS found.。但是,如果我开始编译代码(make VERBOSE=1),库是没有链接的,所以代码无法编译。以下是错误信息:
fatal error: cblas.h: No such file or directory
#include <cblas.h>
^~~~~~~~~
compilation terminated.我成功地安装了OpenBLAS。头文件在/opt/OpenBLAS/include中,共享库在/opt/OpenBLAS/lib中。我的操作系统是ubuntu 18.04。
有什么帮助吗?谢谢!
发布于 2020-01-03 23:10:15
谢谢Tsyvarev。我找到问题了。
我尝试使用message()打印出变量。
message(${BLAS_LIBRARIES})这就给出了:
/opt/OpenBLAS/lib/libopenblas.so这样就找到了共享库。
但是,对于BLAS_INCLUDE_DIRS,它提供了:
message(${BLAS_INCLUDE_DIRS})
CMake Error at CMakeLists.txt:27 (message):
message called with incorrect number of arguments事实证明,FindBLAS变量中不包含BLAS_INCLUDE_DIRS。因此,我手动添加了include头文件:
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(/opt/OpenBLAS/include/)
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)这一次,它编译时没有错误。除了使用include_directories(),您还可以尝试使用find_path() (check this)。
https://stackoverflow.com/questions/59548308
复制相似问题