gianfrdp/SDM120C

Libmodbus 3.1.4 & SDM 120c on ARM

Closed this issue · 1 comments

Hello,

I 've got trouble while installing SDM on my Odroid (ARMv7).
Installation of libmodbus 3.1.4 seems ok but SDM gives some errors.
See the history below...
What do you think about it ?
Thanks by advance for your answer.

root@odroid:/home/libmodbus/libmodbus-3.1.4# make install
Making install in src
/bin/mkdir -p '/usr/local/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libmodbus.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libmodbus.so.5.1.0 /usr/local/lib/libmodbus.so.5.1.0
libtool: install: (cd /usr/local/lib && { ln -s -f libmodbus.so.5.1.0 libmodbus.so.5 || { rm -f libmodbus.so.5 && ln -s libmodbus.so.5.1.0 libmodbus.so.5; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libmodbus.so.5.1.0 libmodbus.so || { rm -f libmodbus.so && ln -s libmodbus.so.5.1.0 libm odbus.so; }; })
libtool: install: /usr/bin/install -c .libs/libmodbus.lai /usr/local/lib/libmodbus.la

libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/sbin" ldconfig -n /usr/loc al/lib

Libraries have been installed in:
/usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:

  • add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
    during execution
  • add LIBDIR to the 'LD_RUN_PATH' environment variable
    during linking
  • use the '-Wl,-rpath -Wl,LIBDIR' linker flag
  • have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

/bin/mkdir -p '/usr/local/include/modbus'
/usr/bin/install -c -m 644 modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h '/usr/local/include/modbus'
Making install in doc
make[2]: Nothing to be done for install-exec-am'. Making install in tests make[2]: Nothing to be done forinstall-exec-am'.
make[2]: Nothing to be done for install-data-am'. make[2]: Nothing to be done forinstall-exec-am'.
/bin/mkdir -p '/usr/local/share/doc/libmodbus'
/usr/bin/install -c -m 644 MIGRATION README.md '/usr/local/share/doc/libmodbus'
/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libmodbus.pc '/usr/local/lib/pkgconfig'
root@odroid:/home/libmodbus/libmodbus-3.1.4# cd ..
root@odroid:/home/libmodbus# cd ../SDM
root@odroid:/home/SDM# export LD_RUN_PATH=/usr/local/lib
root@odroid:/home/SDM# make clean
rm -f .o sdm120c
root@odroid:/home/SDM# make
gcc -c -o sdm120c.o sdm120c.c -O2 -Wall -g pkg-config --cflags libmodbus
gcc -c -o RS485_lock.o RS485_lock.c -O2 -Wall -g pkg-config --cflags libmodbus
gcc -c -o log.o log.c -O2 -Wall -g pkg-config --cflags libmodbus
log.c: In function ‘log_message’:
log.c:59:8: warning: format not a string literal and no format arguments [-Wformat-security]
fprintf(stderr, buffer);
^
log.c:68:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, versionbuffer);
^
log.c:71:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, parent);
^
log.c:72:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, cmdline);
^
log.c:75:9: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, buffer);
^
gcc -O2 -Wall -g pkg-config --libs libmodbus -o sdm120c sdm120c.o RS485_lock.o log.o
sdm120c.o: In function exit_error': /home/SDM/sdm120c.c:228: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:229: undefined reference to modbus_free' sdm120c.o: In functiongetMeasureFloat':
/home/SDM/sdm120c.c:358: undefined reference to modbus_read_input_registers' /home/SDM/sdm120c.c:364: undefined reference tomodbus_strerror'
/home/SDM/sdm120c.c:363: undefined reference to modbus_strerror' /home/SDM/sdm120c.c:364: undefined reference tomodbus_strerror'
sdm120c.o: In function readRegisters': /home/SDM/sdm120c.c:452: undefined reference tomodbus_read_input_registers'
/home/SDM/sdm120c.c:458: undefined reference to modbus_strerror' /home/SDM/sdm120c.c:457: undefined reference tomodbus_strerror'
/home/SDM/sdm120c.c:458: undefined reference to modbus_strerror' sdm120c.o: In functiongetConfigBCD':
/home/SDM/sdm120c.c:509: undefined reference to modbus_read_registers' /home/SDM/sdm120c.c:512: undefined reference tomodbus_strerror'
sdm120c.o: In function changeConfigHex': /home/SDM/sdm120c.c:552: undefined reference tomodbus_write_registers'
/home/SDM/sdm120c.c:557: undefined reference to modbus_strerror' sdm120c.o: In functionchangeConfigFloat':
/home/SDM/sdm120c.c:568: undefined reference to modbus_set_float' /home/SDM/sdm120c.c:580: undefined reference tomodbus_write_registers'
/home/SDM/sdm120c.c:585: undefined reference to modbus_strerror' sdm120c.o: In functionchangeConfigBCD':
/home/SDM/sdm120c.c:603: undefined reference to modbus_write_registers' /home/SDM/sdm120c.c:608: undefined reference tomodbus_strerror'
sdm120c.o: In function main': /home/SDM/sdm120c.c:1044: undefined reference tomodbus_new_rtu'
/home/SDM/sdm120c.c:1065: undefined reference to modbus_set_byte_timeout' /home/SDM/sdm120c.c:1068: undefined reference tomodbus_set_response_timeout'
/home/SDM/sdm120c.c:1096: undefined reference to modbus_set_error_recovery' /home/SDM/sdm120c.c:1102: undefined reference tomodbus_connect'
/home/SDM/sdm120c.c:1118: undefined reference to modbus_set_slave' /home/SDM/sdm120c.c:1460: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:1461: undefined reference to modbus_free' /home/SDM/sdm120c.c:1062: undefined reference tomodbus_set_byte_timeout'
/home/SDM/sdm120c.c:1227: undefined reference to modbus_close' /home/SDM/sdm120c.c:1228: undefined reference tomodbus_free'
/home/SDM/sdm120c.c:1210: undefined reference to modbus_close' /home/SDM/sdm120c.c:1211: undefined reference tomodbus_free'
/home/SDM/sdm120c.c:1099: undefined reference to modbus_set_debug' /home/SDM/sdm120c.c:1220: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:1221: undefined reference to modbus_free' /home/SDM/sdm120c.c:1103: undefined reference tomodbus_strerror'
collect2: error: ld returned 1 exit status
make: *
* [sdm120c] Error 1
root@odroid:/home/SDM# sdm120c -a2 -b9600 -z3 -2 -qpievfg /dev/ttyUSB1
NOK

Please change Makefile according to libmodbus installation.

orangepi@orangepipc:~$ wget -c https://libmodbus.org/releases/libmodbus-3.1.4.tar.gz
orangepi@orangepipc:~$ tar zxvf libmodbus-3.1.4.tar.gz
orangepi@orangepipc:~$ cd libmodbus-3.1.4
orangepi@orangepipc:~/libmodbus-3.1.4$ ./configure
orangepi@orangepipc:~/libmodbus-3.1.4$ make
orangepi@orangepipc:~/libmodbus-3.1.4$ sudo make install
orangepi@orangepipc:~$ git clone https://github.com/gianfrdp/SDM120C.git
orangepi@orangepipc:~$ cd SDM120C/
orangepi@orangepipc:~/SDM120C$ sed -i -s 's|pkg-config --cflags libmodbus|-I/usr/local/include/modbus|g' Makefile
orangepi@orangepipc:~/SDM120C$ sed -i -s 's|pkg-config --libs libmodbus|-L/usr/local/lib -lmodbus|g' Makefile
orangepi@orangepipc:~/SDM120C$ sed -i -s 's|`||g' Makefile

orangepi@orangepipc:~/SDM120C$ cat Makefile
CC = gcc
CFLAGS = -O2 -Wall -g -I/usr/local/include/modbus
LDFLAGS = -O2 -Wall -g -L/usr/local/lib -lmodbus

SDM = sdm120c
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)

${SDM}: sdm120c.o
$(CC) -o $@ sdm120c.o $(LDFLAGS)
chmod 4711 ${SDM}

strip:
strip ${SDM}

clean:
rm -f *.o ${SDM}

install: ${SDM}
install -m 4711 $(SDM) /usr/local/bin

uninstall:
rm -f /usr/local/bin/$(SDM)

orangepi@orangepipc:~/SDM120C$ make
gcc -c -o sdm120c.o sdm120c.c -O2 -Wall -g -I/usr/local/include/modbus
gcc -o sdm120c sdm120c.o -O2 -Wall -g -L/usr/local/lib -lmodbus
chmod 4711 sdm120c

orangepi@orangepipc:~/SDM120C$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ ./sdm120c
sdm120c 1.3.5.3: ModBus RTU client to read EASTRON SDM120C smart mini power meter registers

orangepi@orangepipc:~/SDM120C$ cat /etc/ld.so.conf.d/libc.conf
/usr/local/lib

orangepi@orangepipc:~/SDM120C$ sudo ldconfig
orangepi@orangepipc:~/SDM120C$ sudo ldconfig -p | grep local
libmodbus.so.5 (libc6,hard-float) => /usr/local/lib/libmodbus.so.5
libmodbus.so (libc6,hard-float) => /usr/local/lib/libmodbus.so

orangepi@orangepipc:~/SDM120C$ ./sdm120c
sdm120c 1.3.5.3: ModBus RTU client to read EASTRON SDM120C smart mini power meter registers