![链接器未找到 libsystemd](https://linux22.com/image/1164474/%E9%93%BE%E6%8E%A5%E5%99%A8%E6%9C%AA%E6%89%BE%E5%88%B0%20libsystemd.png)
我正在尝试编写一个systemd
使用看门狗的服务,之后
sudo apt install libsystemd-dev
我检查了一下以确保它可用:
$ ldconfig -p |grep systemd
libsystemd.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libsystemd.so.0
libsystemd.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libsystemd.so
libnss_systemd.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libnss_systemd.so.2
然后检查以确保链接器可以找到它:
$ echo "int main(){}" | gcc -x c++ -Wl,--no-as-needed -llibsystemd - && ldd a.out | grep libsystemd
/usr/bin/ld: cannot find -llibsystemd
collect2: error: ld returned 1 exit status
为何找不到ld
?
答案1
-llibsystemd
不寻找libsystemd
- 它寻找liblibsystemd
正如所指出的man g++
:
-l library The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.
所以你要-lsystemd
echo "int main(){}" | gcc -x c++ -Wl,--no-as-needed -lsystemd - && ldd a.out | grep libsystemd