0

I'm new to cmake.

I've installed gsl library with conda.
I first used find_package(gsl REQUIRED) but
cmake didn't find neither "Findgsl.cmake" nor "gslConfig.cmake".
So I tried to use find_library() and find_path() :

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 11)

project(projTEST)

find_library(GSL_LIBRARY gsl "/home/albator/miniconda3/envs/test/lib/" REQUIRED)
find_path(GSL_INCLUDE_DIR gsl "/home/albator/miniconda3/envs/test/include/")

message(STATUS "gsl include dirs: " ${GSL_INCLUDE_DIR})
message(STATUS "gsl lib dirs: " ${GSL_LIBRARY})

set(SRCS
main.cpp)

set(HDRS
)

add_executable(test ${SRCS} ${HDRS} )
set_target_properties(test PROPERTIES LINKER_LANGUAGE CXX )
target_link_libraries(test ${GSL_LIBRARY})
target_include_directories(test PRIVATE ${GSL_INCLUDE_DIR})

install(TARGETS test 
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}
ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}
)

but when I compile #include <gsl/gsl_sf_bessel.h> is not found...

Could someone tell me what I'm doing wrong ?

Botje
  • 26,269
  • 3
  • 31
  • 41
albator
  • 93
  • 7
  • Do you have the mentioned CMake files on your system? You may need to point Cmake to that path first. – Botje Oct 05 '20 at 09:28
  • @Botje In fact I haven't found the "Findgsl.cmake" nor "gslConfig.cmake" on my system. So I tried directly to link the library and the headers files... – albator Oct 05 '20 at 09:40
  • FindGSL.cmake has been part of the CMake distribution since CMake 3.2. Are you sure it is not packaged with CMake? Or are you running an ancient CMake? – Botje Oct 05 '20 at 09:42
  • @Botje I use cmake version 3.16.3. I haven't found any file .cmake delivered with the gsl library. And I reinstalled gsl with conda but none .cmake file appeared... – albator Oct 05 '20 at 09:49
  • No, FindGSL.cmake should be part of your **CMake** installation. – Botje Oct 05 '20 at 09:52
  • @Botje You're right ! I've found FindGSL.cmake in /usr/share/cmake-3.16/Modules. But find_package() is not supposed to find it automatically ? I forgot to precise that I use Cmake with vscode. I don't know if it makes a difference... – albator Oct 05 '20 at 10:05
  • Did you actually write `find_package(gsl REQUIRED)` or did you write `find_package(GSL REQUIRED)` ? Linux systems are case-sensitive, so is CMake. – Botje Oct 05 '20 at 10:06
  • @Botje I used `find_package(gsl REQUIRED)`. With `find_package(GSL REQUIRED)` I have another error: ``` CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message): Could NOT find GSL (missing: GSL_CBLAS_LIBRARY) (found version "") ``` – albator Oct 05 '20 at 10:12
  • That means CMake was running the FindGSL.cmake script but failed to find GSL. The hints on the [linked reference](https://cmake.org/cmake/help/latest/module/FindGSL.html) page (thanks @Tsyvarev!) does mention that should set GSL_ROOT_DIR. – Botje Oct 05 '20 at 10:15
  • @Botje Thanks for your help. find_package seems working now. But I 've still a problem when I compile : the header file #include is not found... – albator Oct 05 '20 at 10:45
  • Make sure to `target_link_libraries(test GSL::gsl)` to properly configure the header and library paths. – Botje Oct 05 '20 at 10:46
  • @Botje I do the same like in this link [https://stackoverflow.com/questions/44821615/linking-gsl-in-cmakelists-txt] but without success... – albator Oct 05 '20 at 10:52
  • Ask a new question then, with your code and your error message. – Botje Oct 05 '20 at 10:54
  • @Botje it works! I delete and rebuild everything. Thanks a lot for your help! – albator Oct 05 '20 at 10:57

0 Answers0