I have a big project and now I need to include some functions from GSL.
This is my CMakeFile I run under QtCreator
project(numerics LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set(INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/maths
${CMAKE_CURRENT_SOURCE_DIR}/include/maths/vectors_matrices
${CMAKE_CURRENT_SOURCE_DIR}/include/physics
${CMAKE_CURRENT_SOURCE_DIR}/include/physics/alpha-d_potentials
${CMAKE_CURRENT_SOURCE_DIR}/include/physics/NN_potentials
${CMAKE_CURRENT_SOURCE_DIR}/include/physics/four_vectors_tensors
${CMAKE_CURRENT_SOURCE_DIR}/tests
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_master_thesis
${CMAKE_CURRENT_SOURCE_DIR}/tests/av18
)
set (GSL_INCLUDE_DIR
/home/alessandro/gsl/lib
)
set(SRC_DIR
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/maths
${CMAKE_CURRENT_SOURCE_DIR}/src/maths/vectors_matrices
${CMAKE_CURRENT_SOURCE_DIR}/src/physics
${CMAKE_CURRENT_SOURCE_DIR}/src/physics/four_vectors_tensors)
set(HEADERS
include/maths/Angle.hpp
include/maths/Matrix.hpp
include/maths/Complex.hpp
include/physics/Physics_constants.hpp
include/physics/Physics_utils.hpp
include/maths/Row.hpp
include/maths/Column.hpp
include/maths/LU_decomposition.hpp
include/maths/CG-3J-6J.hpp
include/maths/SphericalBesselJ.hpp
include/maths/Function.hpp
include/maths/Laguerre.hpp
include/physics/SphericalHarmonics.hpp
include/physics/alpha-d_potentials/alpha-d_potential_Hammache.hpp
include/physics/alpha-d_potentials/alpha-d_potential_Tursunov.hpp
include/physics/alpha-d_potentials/alpha-d_potential_Mukhamedzhanov.hpp
include/physics/alpha-d_potentials/alpha-d_potential_Dubovichenko.hpp
include/maths/Numerov.hpp
include/maths/DerivativeFixedStep.hpp
include/maths/Factorial.hpp
include/maths/utilities.hpp
include/maths/Integration_Trapezoidal.hpp
include/maths/find_zero_Newton.h
include/maths/abs.hpp
include/maths/norm.hpp
include/physics/NN_potentials/av18.hpp
include/maths/Variational_bound.hpp
include/maths/Integration_B5.hpp
include/maths/Phochammer.hpp
include/physics/Potentials.hpp
include/physics/PotentialData.hpp
src/physics/PotentialData.cpp
)
SET(SOURCES
src/physics/NN_potentials/av18.cpp
)
include_directories(${INCLUDE_DIR} ${SRC_DIR})
add_executable(Physics main.cpp ${SOURCES} ${HEADERS})
add_executable(tests ${SOURCES} tests/tests.cpp tests/zip.hpp
tests/test_numerov.hpp
tests/test_CG_3J_6J.hpp
tests/test_spherical_bessel_j.hpp
tests/test_Laguerre.hpp
tests/test_ylm.h
tests/test_master_thesis/test_numerov_lithium_Hammache.hpp
tests/test_master_thesis/test_numerov_lithium_Tursunov.hpp
tests/test_master_thesis/test_numerov_lithium_Mukhamedzhanov.hpp
tests/test_master_thesis/test_numerov_lithium_Dubovichenko.hpp
tests/test_derivative_fixed_step.hpp
tests/av18/test_numerov_AV18.hpp
tests/test_master_thesis/test_variational_lithium_Hammache.hpp
tests/test_master_thesis/test_variational_lithium_Tursunov.hpp
tests/test_master_thesis/test_variational_lithium_Mukhamedzhanov.hpp
tests/test_master_thesis/test_variational_lithium_Dubovichenko.hpp
tests/av18/test_variational_AV18.hpp
)
find_package(GSL REQUIRED)
find_package(LAPACK REQUIRED)
target_compile_features(Physics PRIVATE cxx_std_17)
target_include_directories(Physics PRIVATE ${INCLUDE_DIR} ${GSL_INCLUDE_DIR})
target_link_libraries(Physics GSL::gsl GSL::gslcblas ${lapackblas_libraries} ${LAPACKE_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
install(TARGETS Physics
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
target_include_directories(tests PRIVATE ${INCLUDE_DIRS})
target_compile_options(tests PRIVATE -Wall)
find_package(GTest REQUIRED)
target_link_libraries(tests GTest::GTest pthread ${lapackblas_libraries} ${LAPACKE_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
I have no problems running CMake from qtcreator, but when I build it fails to find the GSL function I am using. The error is
...path.../utilities.hpp:27: error: undefined reference to `gsl_sf_coulomb_wave_FG_e'
Firsly I followed the instructions to install GSL directly from the downloaded tar. I could run the test code, after changing one of the environmental variable in the shell (it could not find the linked library needed otherwise).
After fixing this I tried to use it in the qtcreator environment, but it could not find GSL, so following an advise found online I installed libgsl-dev. Now qtcreator could find GSL and I could include it in the headers, it could also help with self completing the function name and arguments.
Unfortunately when building it I got the forementioned error.
I also tried to take the piece of program in the project and compile it with g++ test -lgs and it compiled and run fine.
The test program is this
#include <cmath>
#include "gsl/gsl_sf_coulomb.h"
template<class T>
struct CoulombSolutions {
T F;
T G;
T Fp;
T Gp;
double l;
double eta;
CoulombSolutions( T F, T G, T Fp, T Gp, double l, double eta)
: F(F),G(G), Fp(Fp), Gp(Gp), l(l), eta(eta) {}
};
template<class T>
CoulombSolutions<T> coulomb(T eta, int l, double x) {
gsl_sf_result F, Fp, G, Gp;
double l_F = (double) l;
double k_l_G = 0, expF, expG;
gsl_sf_coulomb_wave_FG_e(eta,x,l_F,k_l_G,&F,&Fp,&G,&Gp,&expF,&expG);
return CoulombSolutions<T>(F.val,G.val,Fp.val,Gp.val,l_F,eta);
}
int main() {
double eta = 2.15;
int l = 0;
double x = 5.;
auto res = coulomb<double>(eta,l,x);
std::cout << res.F << std::endl;
}
What might be the problem?