CMake Error: The following variables are used in this project, but they are set to NOTFOUND.解决

一、问题展示

使用cmake时,提示错误如下

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBOSMOCODEC_LIBRARY (ADVANCED)
    linked by target "grgsm" in directory /home/root/gr-gsm/lib
LIBOSMOCODING_LIBRARY (ADVANCED)
    linked by target "grgsm" in directory /home/root/gr-gsm/lib
LIBOSMOCORE_LIBRARY (ADVANCED)
    linked by target "grgsm" in directory /home/root/gr-gsm/lib
LIBOSMOGSM_LIBRARY (ADVANCED)
    linked by target "grgsm" in directory /home/root/gr-gsm/lib

二、解决

解决方法1

这个错误信息是由于缺少一些依赖库,导致 CMake 无法找到这些库。其中 LIBOSMOCODEC_LIBRARY、LIBOSMOCODING_LIBRARY、LIBOSMOCORE_LIBRARY 和 LIBOSMOGSM_LIBRARY 这四个变量都没有被正确设置。

1.查找LIBOSMOCODEC_LIBRARY、LIBOSMOCODING_LIBRARY、LIBOSMOCORE_LIBRARY 和 LIBOSMOGSM_LIBRARY的路径

#查找上述变量
find / -name "libosmocodec.*"
find / -name "libosmocoding.*"
find / -name "libosmocore.*"
find / -name "libosmogsm.*"

2.如果找不到,检查是否已经安装上述库

#检查是否安装
dpkg -L libosmocore-dev | grep -E 'libosmocodec|libosmocoding|libosmocore|libosmogsm'
#如果没有安装,比如显示 dpkg-query: package 'libosmocore-dev' is not installed

#解决(其余包没有安装的同理)
#查看软件包安装状态
dpkg -s libosmocore-dev
#安装
sudo apt-get install libosmocore-dev

3.如果已经安装了这些库却仍然出现问题,请尝试设置这些变量的路径。请在终端中运行以下命令(其实,安装完毕上述包后,直接执行第四步好像也可以,你可以试试,说不定可以)

export LIBOSMOCODEC_LIBRARY=/path/to/LIBOSMOCODEC_LIBRARY
export LIBOSMOCODING_LIBRARY=/path/to/LIBOSMOCODING_LIBRARY
export LIBOSMOCORE_LIBRARY=/path/to/LIBOSMOCORE_LIBRARY
export LIBOSMOGSM_LIBRARY=/path/to/LIBOSMOGSM_LIBRARY

将上述命令中的 /path/to 替换为实际的库路径。
4.运行完上述命令之后,重新运行 CMake 命令即可

cd /home/root/gr-gsm/build
cmake ..

解决方法2

如果上述方法仍然不起作用,请更改 CMakeLists.txt 文件来手动链接这些库。打开 CMakeLists.txt 文件,找到 LIBRARY 相关的部分,并添加以下语句:

TARGET_LINK_LIBRARIES(grgsm
  ${LIBOSMOCODEC_LIBRARY}
  ${LIBOSMOCODING_LIBRARY}
  ${LIBOSMOCORE_LIBRARY}
  ${LIBOSMOGSM_LIBRARY}
)

保存文件并重新运行 CMake 命令。

如果想了解更多关于计算机、网络安全相关知识,请微信搜索公众号 MiaoA知识

你可能感兴趣的:(Hackrf,One教程,linux,服务器)