编译基于libmodbus
库的应用程序时遇到问题:https://github.com/stephane/libmodbus
我尝试使用以下命令编译它:cc pkg-config --cflags --libs libmodbus modbus.c -o modbus
但我得到以下错误:
/usr/bin/ld: /tmp/cckdtbWy.o: in function `main':
modbus.c:(.text+0x1b): undefined reference to `modbus_new_tcp_pi'
/usr/bin/ld: modbus.c:(.text+0x5c): undefined reference to `modbus_connect'
/usr/bin/ld: modbus.c:(.text+0x8d): undefined reference to `modbus_free'
/usr/bin/ld: modbus.c:(.text+0xa3): undefined reference to `modbus_connect'
/usr/bin/ld: modbus.c:(.text+0xde): undefined reference to `modbus_read_bits'
/usr/bin/ld: modbus.c:(.text+0x11e): undefined reference to `modbus_close'
/usr/bin/ld: modbus.c:(.text+0x12a): undefined reference to `modbus_free'
collect2: error: ld returned 1 exit status
我会感激任何帮助!
顺祝商祺!
2条答案
按热度按时间iyr7buue1#
您是否安装了
libmodbus-dev
?您应该尝试以下操作:sudo apt-get install -y libmodbus-dev
.参见v3.1.6和v3.0.8:libmodbus docs
wi3ka0sx2#
I have worked through this problem and my solution is that:
1. Create
modbus.conf
file in/etc/ld.so.conf.d/
.2. Run
sudo ldconfig
.3. Compile your application/program with the following command:
gcc <name>.c -o <name> -I/usr/local/include/modbus/ -lmodbus
It has worked for me, but I am not sure whether the first step is necessary.