gpt4 book ai didi

无法将 BLAS 库与 Clion 2016.1.2 和 Fedora 22 链接,获取 undefined reference

转载 作者:太空宇宙 更新时间:2023-11-04 03:30:03 25 4
gpt4 key购买 nike

今天一整天我都在为这个问题苦苦挣扎。我相信我在 CMake 中遗漏了一些小东西,因为这是我现在第一次使用它,而且我遇到了所有这些错误。

我的问题是,无论我如何更改或在 Cmake 文件中包含什么,我都会不断收到此错误。

[ 25%] Linking CXX executable Matrix_Benchmark
CMakeFiles/Matrix_Benchmark.dir/main.cpp.o: In function `run_benchmark(double*, double*, double*, int, int, int, int)':
/home/lumx/git_projects/memory-traces/src/Matrix_Benchmark/main.cpp:202: undefined reference to `cblas_dgemm'
collect2: error: ld returned 1 exit status

我认为 Blas 和 OpenBlas 存在问题,因为没有带有 blas 或 blas-devel 包的 cblas.h 为此,我必须安装 OpenBlas 和开发库。

到目前为止我尝试了很多东西,我将包括我现在拥有的有点困惑的 Cmake 文件。我对此感到抱歉,但我希望有人能发现更多错误并帮助我改进这些错误。

cmake_minimum_required(VERSION 3.5)
#set( CMAKE_VERBOSE_MAKEFILE on )
set( CMAKE_VERBOSE_MAKEFILE off )
project(Matrix_Benchmark)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wfatal-errors -Wall -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wfatal-errors -Wall -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

#https://github.com/BVLC/caffe/blob/master/cmake/Modules/FindOpenBLAS.cmake
SET(Open_BLAS_INCLUDE_SEARCH_PATHS
/usr/include
/usr/include/openblas
/usr/include/openblas-base
/usr/local/include
/usr/local/include/openblas
/usr/local/include/openblas-base
/opt/OpenBLAS/include
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/include
)

SET(Open_BLAS_LIB_SEARCH_PATHS
/lib/
/lib/openblas-base
/lib64/
/usr/lib
/usr/lib/openblas-base
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/OpenBLAS/lib
$ENV{OpenBLAS}cd
$ENV{OpenBLAS}/lib
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/lib
)

FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})

SET(OpenBLAS_FOUND ON)

# Check include files
IF(NOT OpenBLAS_INCLUDE_DIR)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off")
ENDIF()

# Check libraries
IF(NOT OpenBLAS_LIB)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off")
ENDIF()

IF (OpenBLAS_FOUND)
IF (NOT OpenBLAS_FIND_QUIETLY)
MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}")
MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}")
ENDIF (NOT OpenBLAS_FIND_QUIETLY)
ELSE (OpenBLAS_FOUND)
IF (OpenBLAS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find OpenBLAS")
ENDIF (OpenBLAS_FIND_REQUIRED)
ENDIF (OpenBLAS_FOUND)

MARK_AS_ADVANCED(
OpenBLAS_INCLUDE_DIR
OpenBLAS_LIB
OpenBLAS
)

find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message(WARNING "BLAS FOUND")
link_directories(${OpenBLAS_LIB})
#link_directories(/usr/lib64/libopenblas.so)
message(WARNING ${BLAS_LIBRARIES} " asd " ${OpenBLAS_LIB} " asdfasd " ${OpenBLAS_INCLUDE_DIR})
add_library(OpenBlas /usr/include/openblas/cblas.h)
else(BLAS_FOUND)
message(FATAL_ERROR "BLAS NOT FOUND")
endif(BLAS_FOUND)

if(OpenBLAS_FOUND)
message(WARNING "OpenBLAS FOUND")
link_directories(${BLAS_LIBRARIES})
#link_directories(/usr/lib64/libopenblas.so)
message(WARNING ${OpenBLAS_FOUND} " asd " ${BLA_VENDOR} )
#add_library(OpenBlas /usr/include/openblas/cblas.h)
else(OpenBLAS_FOUND)
message(FATAL_ERROR "BLAS NOT FOUND")
endif(OpenBLAS_FOUND)

find_package(LAPACK REQUIRED)
if(LAPACK_FOUND)
message(WARNING "LAPACK FOUND")
link_directories(${LAPACK_LIBRARIES})
message(WARNING ${LAPACK_LIBRARIES})
else(LAPACK_FOUND)
message(FATAL_ERROR "LAPACK NOT FOUND")
endif(LAPACK_FOUND)


set(SOURCE_FILES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenBLAS_INCLUDE_DIR} main.cpp MatrixMarket/mmio.c MatrixMarket/iohb.c )
add_executable(Matrix_Benchmark ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenBLAS_INCLUDE_DIR} ${SOURCE_FILES})

if(BLAS_FOUND)
target_link_libraries (Matrix_Benchmark ${BLAS_LIBRARIES})
endif(BLAS_FOUND)

if(LAPACK_FOUND)
target_link_libraries ( Matrix_Benchmark ${LAPACK_LIBRARIES})
endif(LAPACK_FOUND)

# copy data folder to build (not working, have to fix it)
file(GLOB dataFiles "${CMAKE_CURRENT_BINARY_DIR}/data/")
#file( GLOB_RECURSE dataFiles RELATIVE "${CMAKE_CURRENT_BINARY_DIR}" "data/*.*)
#file( GLOB_RECURSE pattern_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "patterns/*.vti" )
#add_custom_target(copy)
foreach(dataFile ${dataFiles})
message(WARNING "ASDASDASD")
message(WARNING ${dataFolder})
#set (dest "${PROJECT_BINARY_DIR}/${copyDataFiles}")
#SET (dest2 "${CMAKE_CURRENT_BINARY_DIR}/${copyDataFiles}")
message(WARNING " Copying ${dest}")
add_custom_command(
TARGET dataFile POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_BINARY_DIR}/${dataFiles} ${CMAKE_SOURCE_DIR}/data/
)
#SET (dest2 "${CMAKE_CURRENT_BINARY_DIR}/${copyDataFiles}")
#MESSAGE(STATUS " Copying ${dest2}")
endforeach(dataFile)

我也有 cblas.h 的 include 指令来处理 C 和 C++

#ifdef __cplusplus
extern "C"
{
#endif
#include <openblas/cblas.h>
#ifdef __cplusplus
}
#endif

最佳答案

好的,修复了它。

我没有在 CMake 文件中包含 OpenBlas lib,出于某些原因,我不得不删除所有 Blas、OpenBlas、Lapack 包并重新安装它们。同样出于某种原因,我不得不重新启动系统以使其正常工作。这很奇怪,但谁知道发生了什么。

现在 CMake 文件看起来像

    cmake_minimum_required(VERSION 3.5)
#set( CMAKE_VERBOSE_MAKEFILE on )
set( CMAKE_VERBOSE_MAKEFILE off )
project(Matrix_Benchmark)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wfatal-errors -Wall -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wfatal-errors -Wall -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

#https://github.com/BVLC/caffe/blob/master/cmake/Modules/FindOpenBLAS.cmake
SET(Open_BLAS_INCLUDE_SEARCH_PATHS
/usr/include
/usr/include/openblas
/usr/include/openblas-base
/usr/local/include
/usr/local/include/openblas
/usr/local/include/openblas-base
/opt/OpenBLAS/include
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/include
)

SET(Open_BLAS_LIB_SEARCH_PATHS
/lib/
/lib/openblas-base
/lib64/
/usr/lib
/usr/lib/openblas-base
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/OpenBLAS/lib
$ENV{OpenBLAS}cd
$ENV{OpenBLAS}/lib
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/lib
)

FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})

SET(OpenBLAS_FOUND ON)

# Check include files
IF(NOT OpenBLAS_INCLUDE_DIR)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off")
ENDIF()

# Check libraries
IF(NOT OpenBLAS_LIB)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off")
ENDIF()

IF (OpenBLAS_FOUND)
IF (NOT OpenBLAS_FIND_QUIETLY)
MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}")
MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}")
ENDIF (NOT OpenBLAS_FIND_QUIETLY)
ELSE (OpenBLAS_FOUND)
IF (OpenBLAS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find OpenBLAS")
ENDIF (OpenBLAS_FIND_REQUIRED)
ENDIF (OpenBLAS_FOUND)

MARK_AS_ADVANCED(
OpenBLAS_INCLUDE_DIR
OpenBLAS_LIB
OpenBLAS
)

find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message(WARNING "BLAS_LIB FOUND at " ${BLAS_LIBRARIES} " include files " )
link_directories(${BLAS_LIBRARIES})
else(BLAS_FOUND)
message(FATAL_ERROR "BLAS NOT FOUND")
endif(BLAS_FOUND)

if(OpenBLAS_FOUND)
message(WARNING "OpenBLAS_LIB FOUND at " ${OpenBLAS_LIB} ", include files " ${OpenBLAS_INCLUDE_DIR})
link_directories(${OpenBLAS_LIB})
#add_library(${OpenBLAS_INCLUDE_DIR})
else(OpenBLAS_FOUND)
message(FATAL_ERROR "OpenBLAS_FOUND NOT FOUND")
endif(OpenBLAS_FOUND)

find_package(LAPACK REQUIRED)
if(LAPACK_FOUND)
message(WARNING "LAPACK_LIB FOUND at " ${LAPACK_LIBRARIES} ", include files " )
link_directories(${LAPACK_LIBRARIES})
else(LAPACK_FOUND)
message(FATAL_ERROR "LAPACK NOT FOUND")
endif(LAPACK_FOUND)

set(SOURCE_FILES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenBLAS_INCLUDE_DIR} main.cpp MatrixMarket/mmio.c MatrixMarket/iohb.c )
add_executable(Matrix_Benchmark ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenBLAS_LIB} ${SOURCE_FILES})

if(BLAS_FOUND)
target_link_libraries (Matrix_Benchmark ${BLAS_LIBRARIES})
endif(BLAS_FOUND)

if(OpenBLAS_FOUND)
target_link_libraries (Matrix_Benchmark ${OpenBLAS_LIB})
endif(OpenBLAS_FOUND)

if(LAPACK_FOUND)
target_link_libraries ( Matrix_Benchmark ${LAPACK_LIBRARIES})
endif(LAPACK_FOUND)

# copy data folder to build
file(GLOB dataFiles "${CMAKE_CURRENT_BINARY_DIR}/data/")
#file( GLOB_RECURSE dataFiles RELATIVE "${CMAKE_CURRENT_BINARY_DIR}" "data/*.*)
#file( GLOB_RECURSE pattern_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "patterns/*.vti" )
#add_custom_target(copy)
foreach(dataFile ${dataFiles})
message(WARNING "ASDASDASD")
message(WARNING ${dataFolder})
#set (dest "${PROJECT_BINARY_DIR}/${copyDataFiles}")
#SET (dest2 "${CMAKE_CURRENT_BINARY_DIR}/${copyDataFiles}")
message(WARNING " Copying ${dest}")
add_custom_command(
TARGET dataFile POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_BINARY_DIR}/${dataFiles} ${CMAKE_SOURCE_DIR}/data/
)
#SET (dest2 "${CMAKE_CURRENT_BINARY_DIR}/${copyDataFiles}")
#MESSAGE(STATUS " Copying ${dest2}")
endforeach(dataFile)

关于无法将 BLAS 库与 Clion 2016.1.2 和 Fedora 22 链接,获取 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37515867/

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