Linux: dev: cmake: CHECK_LIBRARY_EXISTS

简介

https://cmake.org/cmake/help/latest/module/CheckLibraryExists.html
这个方法是在Modules/CheckLibraryExists.cmake文件里定义的一个宏。
最终使用的方法是通过现场编译一个文件,里面调用所需要的函数,链接时,使用-labc链接库,然后确定这个库有没有在编译环境安装。其实是分成两步,一个是找相应的.a/.so文件,一个是寻找相应的函数定义。

例子

比如下面这个例子,就是要看“pcre2_match_8” 函数有没有定义,根据输出结果来判断,有没有:

CHECK_LIBRARY_EXISTS(pcre2-8 pcre2_match_8 “” HAVE_PCRE2)
如果没有指定目录,可能会在目录:/usr/lib/gcc/x86_64-redhat-linux/8/…/…/…/…/lib64/libpcre2-8.so

    if(${
   
   VARIABLE})
      
好烦人的系统依赖性关系检查。。 cat@lubancat:~/work/lvgl/demo_linux_port_sdl$ cmake -B ./build -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Error at CMakeLists.txt:13 (find_package): By not providing "FindSDL2_image.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SDL2_image", but CMake did not find one. Could not find a package configuration file provided by "SDL2_image" with any of the following names: SDL2_imageConfig.cmake sdl2_image-config.cmake Add the installation prefix of "SDL2_image" to CMAKE_PREFIX_PATH or set "SDL2_image_DIR" to a directory containing one of the above files. If "SDL2_image" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred! See also "/home/cat/work/lvgl/demo_linux_port_sdl/build/CMakeFiles/CMakeOutput.log". cat@lubancat:~/work/lvgl/demo_linux_port_sdl$ cmake --build ./build make: *** No targets specified and no makefile found. Stop. cat@lubancat:~/work/lvgl/demo_linux_port_sdl$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focal cat@lubancat:~/work/lvgl/demo_linux_port_sdl$
最新发布
06-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mzhan017

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值