FindBLAS with static OpenBLAS 1.10.3
Using CMake 3.6.1, and a OpenBLAS 1.10.3 (build with `NO_SHARED=1`), FindBLAS fails. It is included with: ``` set(BLA_STATIC on) set(BLA_VENDOR OpenBLAS) find_package(BLAS REQUIRED) if (BLAS_FOUND) include_directories(${BLAS_INCLUDE_DIRS}) target_link_libraries(classification ${BLAS_LIBRARIES}) endif() ``` Fails with: ``` -- Looking for sgemm_ -- Looking for sgemm_ - not found CMake Error at /usr/local/share/cmake-3.6/Modules/FindBLAS.cmake:693 (message): A required library with BLAS API not found. Please specify library location. ``` The log from CMakeError.log shows that it fails to find pthreads: ``` Determining if the function sgemm_ exists failed with the following output: Change Dir: <some_path>/build/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/make" "cmTC_5a823/fast" /usr/bin/make -f CMakeFiles/cmTC_5a823.dir/build.make CMakeFiles/cmTC_5a823.dir/build make[1]: Entering directory `<some_path>/build/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_5a823.dir/CheckFunctionExists.c.o /usr/bin/cc -DCHECK_FUNCTION_EXISTS=sgemm_ -o CMakeFiles/cmTC_5a823.dir/CheckFunctionExists.c.o -c /usr/local/share/cmake-3.6/Modules/CheckFunctionExists.c Linking C executable cmTC_5a823 /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5a823.dir/link.txt --verbose=1 /usr/bin/cc -DCHECK_FUNCTION_EXISTS=sgemm_ CMakeFiles/cmTC_5a823.dir/CheckFunctionExists.c.o -o cmTC_5a823 <some_path>/lib/libopenblas.a <some_path>/lib/libopenblas.a(memory.o): In function `openblas_fork_handler': memory.c:(.text+0x1a0): undefined reference to `pthread_atfork' <some_path>/lib/libopenblas.a(blas_server.o): In function `blas_thread_init': blas_server.c:(.text+0x3b4): undefined reference to `pthread_create' <some_path>/lib/libopenblas.a(blas_server.o): In function `goto_set_num_threads': blas_server.c:(.text+0x85a): undefined reference to `pthread_create' <some_path>/lib/libopenblas.a(blas_server.o): In function `blas_thread_shutdown_': blas_server.c:(.text+0xa83): undefined reference to `pthread_join' collect2: error: ld returned 1 exit status make[1]: *** [cmTC_5a823] Error 1 make[1]: Leaving directory `<some_path>/build/CMakeFiles/CMakeTmp' make: *** [cmTC_5a823/fast] Error 2 ``` I resolved this on my machine by setting "pthreads" as the threading type at https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindBLAS.cmake#L179. I see that no other items currently use this, did I build openblas particularly? After changing, that block of code read: ``` if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All") if(NOT BLAS_LIBRARIES) # OpenBLAS (http://www.openblas.net) check_fortran_libraries( BLAS_LIBRARIES BLAS sgemm "" "openblas" "pthreads" ) message("BLAS_LIBRARIES:" ${BLAS_LIBRARIES}) endif() endif () ```
issue