在我的实践中,最好的方法是查找系统中是否存在您的库正在使用locate
和ld
工具:
在文件系统上找到库本身:
locate libssl.a
请注意,它可以显示不再存在的文件的文件系统节点。使用updatedb
前使用locate
。
ld -lssl --verbose
LD_LIBRARY_PATH
通过使用系统变量的链接器查找库:
:~$ ld -lssl --verbose
attempt to open /usr/x86_64-linux-gnu/lib64/libssl.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libssl.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libssl.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libssl.a failed
attempt to open /usr/local/lib64/libssl.so failed
attempt to open /usr/local/lib64/libssl.a failed
attempt to open /lib/x86_64-linux-gnu/libssl.so failed
attempt to open /lib/x86_64-linux-gnu/libssl.a failed
attempt to open /lib64/libssl.so failed
attempt to open /lib64/libssl.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libssl.so succeeded
-lssl (/usr/lib/x86_64-linux-gnu/libssl.so)
libcrypto.so.1.0.0 needed by /usr/lib/x86_64-linux-gnu/libssl.so
found libcrypto.so.1.0.0 at /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
libc.so.6 needed by /usr/lib/x86_64-linux-gnu/libssl.so
found libc.so.6 at /lib/x86_64-linux-gnu/libc.so.6
libdl.so.2 needed by /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
found libdl.so.2 at /lib/x86_64-linux-gnu/libdl.so.2
ld-linux-x86-64.so.2 needed by /lib/x86_64-linux-gnu/libc.so.6
found ld-linux-x86-64.so.2 at /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address
当你尝试找到它时,你会得到这种行为。
那么,当您尝试libssl.a
实际查找 ld 工具执行什么操作时会发生什么?您可以尝试通过运行来调查它ld -l/home/anz/openssl-1.0.1j/libssl.a --verbose
:
ld -l/home/anz/openssl-1.0.1j/libssl.a --verbose`
attempt to open /usr/x86_64-linux-gnu/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/x86_64-linux-gnu/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/x86_64-linux-gnu/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
ld: cannot find -l/home/anz/openssl-1.0.1j/libssl.a
如果你知道什么-l
和-L
ld-options 意味着你就会知道它到底做了什么:后面的所有内容-l
都是你搜索并想要链接的库名称;-L
设置搜索库的路径(在链接过程中附加到链接器自己的列表)。
正确编辑您CMakeLists.txt
的内容以解决此问题。