0

我的应用程序编译有问题,它基于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

我将不胜感激任何帮助!

此致!

4

2 回答 2

0

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.

于 2020-07-29T13:47:41.147 回答
0

你安装了libmodbus-dev吗?你应该试试这个:sudo apt-get install -y libmodbus-dev

请参阅 v3.1.6 和 v3.0.8:libmodbus 文档

于 2020-07-29T00:39:49.913 回答