CMakeLists.txt ----find_package

在linux平台下编译程序的时候通常都会使用到CMakeLists.txt来制定编译规则, 在查找需要链接的lib时候, 通常会使用到find_package, 记录一下我之前用到的地方.

find_package 之后, 最好到FindXXX.cmake中看一下,这个库是怎样使用的.

如果没有特殊指定这个文件的路径, 路径通常是"/usr/share/cmake-XXX/Modules/FindXXX.cmake".

这里边通常会有特定的宏来表示对应的lib路径

This module will set the following variables in your project:
#
# ``OPENSSL_FOUND``
#   System has the OpenSSL library.
# ``OPENSSL_INCLUDE_DIR``
#   The OpenSSL include directory.
# ``OPENSSL_CRYPTO_LIBRARY``
#   The OpenSSL crypto library.
# ``OPENSSL_SSL_LIBRARY``
#   The OpenSSL SSL library.
# ``OPENSSL_LIBRARIES``
#   All OpenSSL libraries.
# ``OPENSSL_VERSION``
#   This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).

顺便记录几条命令:

readelf -d libcurl.so (可以看一下这个so 所链接的其他动态库信息, 其中RUNPATH 指的是优先级最高的目录,如果没有就会到系统目录查找.

Dynamic section at offset 0x71188 contains 33 entries:
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
 0x0000000000000001 (NEEDED)             Shared library: [libssl.so.1.0.0]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypto.so.1.0.0]
 0x0000000000000001 (NEEDED)             Shared library: [libldap_r-2.4.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [liblber-2.4.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-aarch64.so.1]
 0x000000000000000e (SONAME)             Library soname: [libcurl.so.4]
 0x000000000000000c (INIT)               0x9160
 0x000000000000000d (FINI)               0x54008
 0x0000000000000019 (INIT_ARRAY)         0x6e7e8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x6e7f0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x1b8
 0x0000000000000005 (STRTAB)             0x713d8
 0x0000000000000006 (SYMTAB)             0x458
 0x000000000000000a (STRSZ)              6099 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x6ffe8
 0x0000000000000002 (PLTRELSZ)           8376 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x70a8
 0x0000000000000007 (RELA)               0x44c8
 0x0000000000000008 (RELASZ)             11232 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x4428
 0x000000006fffffff (VERNEEDNUM)         5
 0x000000006ffffff0 (VERSYM)             0x4114
 0x000000006ffffff9 (RELACOUNT)          445
 0x0000000000000000 (NULL)               0x0

 

sudo patchelf --set-rpath \$ORIGIN ./libcurl.so.4.5.0 设置so的 RPATH 路径.

你可能感兴趣的:(工具,CMakeLists.txt,---find_package)