我今天整天都在努力解决这个问题。我相信我错过了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
答案 0 :(得分:1)
好的修好了。
我没有包含在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)