Issue
I'm very new to C/C++ and trying to connect to modbus. I am using Eclipse with the following code:
#include <stdio.h>
#include <stdlib.h>
#include <modbus/modbus.h>
int main(void) {
modbus_t *mb = modbus_new_tcp("10.84.4.128", "502");
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
I get the error: src/Modbus.c:17: undefined reference to 'modbus_new_tcp'
In Eclipse I've when to properties and added /usr/include/modbus
to the Library search path (-L)
but still get the above error.
How do I define the reference?
Solution
Don't use
#include <modbus.h>
directly. Instead, include modbus_asc.h
or modbus_rtu.h
or modbus_tcp.h
. This file modbus.h
will be included automatically
Answered By - Shri
Answer Checked By - Gilberto Lyons (JavaFixing Admin)