I have GSL installed and the include<gsl/...> doesn't make the compiler complain, but when I make the code and it wants to actually call the gsl_sf_lnpoch function from gsl, it complains
undefined reference to `gsl_sf_lnpoch'
I Googled and it turns out that having GSL installed is not enough and I need to link CMake and GSL. I am building base on someone's program but am not familiar with how CMake works, and am stuck with this silly bit. I appreciate it if someone tells me what I need to add to the CMakeLists.txt file in below to link make and gsl.
cmake_minimum_required(VERSION 2.8.7)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
include(AppendCompilerFlags)
project(k CXX C)
set(CMAKE_BUILD_TYPE "Release")
#set(CMAKE_BUILD_TYPE "Debug")
# C++11 compiler Check
if(NOT CMAKE_CXX_COMPILER_VERSION) # work around for cmake versions smaller than 2.8.10
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
endif()
if(CMAKE_CXX_COMPILER MATCHES ".*clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()
if( (CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.7) OR
(CMAKE_COMPILER_IS_CLANGXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.2))
message(FATAL_ERROR "Your C++ compiler does not support C++11. Please install g++ 4.7 (or greater) or clang 3.2 (or greater)")
else()
message(STATUS "Compiler is recent enough to support C++11.")
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
append_cxx_compiler_flags("-std=c++11 -Wall -Wextra " "GCC" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-ffast-math -funroll-loops" "GCC" CMAKE_CXX_FLAGS)
else()
append_cxx_compiler_flags("-std=c++11 -Wall" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-stdlib=libc++" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-ffast-math -funroll-loops" "CLANG" CMAKE_CXX_FLAGS)
endif()
include(CheckAVX2)
if( BUILTIN_POPCNT )
if( CMAKE_COMPILER_IS_GNUCXX )
append_cxx_compiler_flags("-msse4.2" "GCC" CMAKE_CXX_FLAGS)
else()
append_cxx_compiler_flags("-msse4.2" "CLANG" CMAKE_CXX_FLAGS)
endif()
message(STATUS "CPU does support fast popcnt.")
else()
message(STATUS "CPU does NOT support fast popcnt")
endif()
add_subdirectory(external/googletest)
include_directories(${CMAKE_HOME_DIRECTORY}/include
${CMAKE_HOME_DIRECTORY}/external/googletest/include
)
add_executable(build.x src/build.cpp)
target_link_libraries(build.x pthread divsufsort divsufsort64)
You're missing the linker flag of the gsl library.
Try
target_link_libraries(... gsl)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With