Ubuntu 22.04编译lon-driver遇sd_notify未定义引用错误求助
编译lon-driver项目时遇到
sd_notify未定义引用错误 问题详情
- 将lon-driver项目克隆至Ubuntu 22.04虚拟机,项目无构建文档且无法获取官方技术支持。
- 执行编译命令
gcc lonifd.c时触发链接错误:
/usr/bin/ld: /tmp/ccJleZ8s.o: in function `main': lonifd.c:(.text+0x3882): undefined reference to `sd_notify' collect2: error: ld returned 1 exit status
- 已将GCC更新至12.3.0版本,版本信息如下:
gcc --version gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- 当前Git版本:
git version 2.34.1
解决方案
sd_notify 是systemd库提供的函数,编译时需要显式链接systemd库。将编译命令修改为:
gcc lonifd.c -lsystemd
如果系统中未安装systemd开发库,需先执行以下命令安装:
sudo apt-get install libsystemd-dev
内容的提问来源于stack exchange,提问作者SPlatten
相关产品推荐
相关产品推荐

