CMakeLists.txt访问GSL库C

时间:2018-12-03 09:56:13

标签: c cmake

尝试在CMake中使用GSL(Ubuntu 18.04)。

根据其安装文件进行安装:

“ sudo sh configure && sudo make && sudo make install”

我的文件夹结构:

Folder Structure

GSL头文件位于/gsl-2.5/gsl /

我的CMakeLists.txt

cmake_minimum_required(VERSION 3.12)
project(neuronalnetwork C)

set(CMAKE_C_STANDARD 99)

add_executable(neuronalnetwork main.c)


include_directories(gsl-2.5/gsl)
LINK_DIRECTORIES(gsl-2.5)
target_link_libraries(main.c gsl)

错误:

CMake Error at CMakeLists.txt:11 (target_link_libraries):
  Cannot specify link libraries for target "main.c" which is not built by
  this project.

如果添加target_link_libraries(neuronalnetwork gsl),则会出现此错误:

更新新错误:

/opt/clion/bin/cmake/linux/bin/cmake --build /home/filip/Projekte/neuronalnetwork/cmake-build-debug --target neuronalnetwork -- -j 4
Scanning dependencies of target neuronalnetwork
[ 50%] Building C object CMakeFiles/neuronalnetwork.dir/main.c.o
[100%] Linking C executable neuronalnetwork
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgeru'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cdotu_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dznrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ddot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdotu_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sdsdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgerc'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scnrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zcopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cherk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zherk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotmg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdotc_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_caxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cdotc_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_saxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_idamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_snrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dger'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dzasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsymv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_isamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zhemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zaxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dcopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_izamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssymv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_chemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgeru'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sger'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgerc'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_chemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dnrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_icamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zhemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotmg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ccopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_daxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csyrk'
collect2: error: ld returned 1 exit status

其他问题的建议无效

1 个答案:

答案 0 :(得分:1)

您的新错误消息告诉您未找到blas库;有关需要添加的链接器标志,请参见gsl example

有关如何通过CMake使用GSL的更多高级详细信息,请查看本征项目的FindGSL.cmake文件。

通常,人们通常会将GSL用作外部依赖项,确定要在代码中包含它吗?

编辑,您应该将GSL用作外部依赖项,只需使用linux软件包管理器将其安装在系统上即可(查找gsl并确保获取头文件)

然后,复制本征的FindGSL.cmake文件,将其复制到某个位置,然后按照此处的操作在您的CMakeLists.txt中

find_package(GSL)
include_directories(${GSL_INCLUDE_DIR})

请注意,如果要将.cmake放在特定目录中,则需要使用告诉CMake在哪里查找

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/where/you/put/the/file/)

编辑2:

为了更加明确,这是您需要的完整代码:

cmake_minimum_required(VERSION 3.12)
project(neuronalnetwork C)

set(CMAKE_C_STANDARD 99)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GSL)

add_executable(neuronalnetwork main.c)
target_include_directories(neuronalnetwork PRIVATE ${PROJECT_SOURCE_DIR} ${GSL_INCLUDE_DIR})
target_link_libraries(neuronalnetwork ${GSL_LIBRARIES})