Compilation issue
Hi,
I am using a ARM based development platform. I have made sure modbus.h exists in the usr/include folder. I am trying to communicate with a plc which is a modbus slave through a C program. The program just opens and closes the connection as I basically wanted to test this function first before I proceeded any further:
# include "stdio.h"
# include "stdlib.h"
# include "modbus/modbus.h"
#define plc 0x01
int main(void)
{
modbus_param_t mb_param;
modbus_
if (modbus_
printf("Not connected\n");
exit(1);
}
modbus_
}
When I compile this program, I am faced with errors:
undefined reference to 'modbus_init_rtu'
undefined reference to 'modbus_connect'
undefined reference to 'modbus_close'
I have doubled checked that these functions do exist in the header file.
I would very much appreciate it if someone could let me know what is wrong with my program and can suggest a solution.
Best Regards,
JM
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- libmodbus Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- JM
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
Could you use the 3.0.X series, please?
Revision history for this message
|
#2 |
Hi Stephane,
DESCRIPTION = "modbuscomm"
SECTION = "examples"
LICENSE = "GPL"
DEPENDS = "libesmtp libyaml"
PR = "r12"
SRC_URI = "file:/
file://modbus.c \
file://modbus.h \
file://
file://modbus-rtu.c \
file://modbus-rtu.h \
file://modbus-tcp.c \
file://
S = "${WORKDIR}"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} mymodbuscomm.c -o mymodbuscomm
${CC} ${CFLAGS} ${LDFLAGS} modbus.c -o modbus.c
${CC} ${CFLAGS} ${LDFLAGS} modbus-data.c -o modbus-data.c
${CC} ${CFLAGS} ${LDFLAGS} modbus-rtu.c -o modbus-rtu.c
${CC} ${CFLAGS} ${LDFLAGS} modbus-tcp.c -o modbus-tcp.c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 mymodbuscomm ${D}${bindir}
install -m 0755 modbus ${D}${bindir}
install -m 0755 modbus-data ${D}${bindir}
install -m 0755 modbus-rtu ${D}${bindir}
install -m 0755 modbus-tcp ${D}${bindir}
}
After I proceeded to bitbake the file I was faced with these errors:
mymodbuscomm.c: In function 'main':
| mymodbuscomm.c:9: error: 'modbus_param_t' undeclared (first use in this function)
| mymodbuscomm.c:9: error: (Each undeclared identifier is reported only once
| mymodbuscomm.c:9: error: for each function it appears in.)
| mymodbuscomm.c:9: error: expected ';' before 'mb_param'
| mymodbuscomm.c:12: error: 'mb_param' undeclared (first use in this function)
| ERROR: Function do_compile failed
Having gone through the other threads that reported similar problems I gathered and made sure all relevant header files and the src folder .c files existed in the same folder as my program. Any further suggestions on how to go about solving these errors would be very much helpful. Thank you and have a great day.
Revision history for this message
|
#3 |
Sorry I had to post my bitbake recipe once more as there was a small typo in the previous post:
DESCRIPTION = "modbuscomm"
SECTION = "examples"
LICENSE = "GPL"
PR = "r12"
SRC_URI = "file:/
file://modbus.c \
file://modbus.h \
file://
file://modbus-rtu.c \
file://modbus-rtu.h \
file://modbus-tcp.c \
file://
S = "${WORKDIR}"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} mymodbuscomm.c -o mymodbuscomm
${CC} ${CFLAGS} ${LDFLAGS} modbus.c -o modbus
${CC} ${CFLAGS} ${LDFLAGS} modbus-data.c -o modbus-data
${CC} ${CFLAGS} ${LDFLAGS} modbus-rtu.c -o modbus-rtu
${CC} ${CFLAGS} ${LDFLAGS} modbus-tcp.c -o modbus-tcp
}
do_install() {
install -d ${D}${bindir}
install -m 0755 mymodbuscomm ${D}${bindir}
install -m 0755 modbus ${D}${bindir}
install -m 0755 modbus-data ${D}${bindir}
install -m 0755 modbus-rtu ${D}${bindir}
install -m 0755 modbus-tcp ${D}${bindir}
}
Thanks,
JM
Revision history for this message
|
#4 |
in the gcc (example:- arm-linux-
example:
/home/karthik/
/home/karthik/
/home/karthik/
for me when i put modbus.
also
do this as shown i mean include all the c files of libmodbus in the command.:-
arm-linux-gcc -o modclient modclient3.c /home/karthik/
Revision history for this message
|
#5 |
The example code you try to compile doesn't use the API of libmodbus 3.0.X
Revision history for this message
|
#6 |
Hi Karthik,
I did copy all the relevant header files to the usr/include/modbus directory as well as including all c files of the libmodus in my bitbake recipe however that did not solve the issue. I am still stuck with the same errors.
Revision history for this message
|
#7 |
Not just that.Whereever the gcc of arm you have extracted you know you have to put there also.If it doesnt work try for instance copying the modbus headerfiles into the directory where your program is present.
Also check the version of libmodbus you are using.I am using libmodbus-3.0.1 version.
Revision history for this message
|
#8 |
Hi Karthik,
Revision history for this message
|
#9 |
Hi,
I would appreciate it if someone who has worked on an ARM Platform and used bitbake to build their applications and ran in to similar errors which I posted in my earlier posts to let me know what changes are required in my bitbake recipe or suggest me anything else that might solve these errors. Thank you very much.
Revision history for this message
|
#10 |
Hi,
Looks like I goofed up installing libmodbus. I'll post again when I uninstall and re-install libmodbus and get it to work. Thanks for your help everyone.
Revision history for this message
|
#11 |
Hi,
I have installed libmodbus again. When I tried to compile the example program bandwidth-
Log data follows:
| /tmp/cckmSANb.o: In function `main':
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
| /home/jm/
In the usr/include/modbus folder I made sure that I changed 'include"modbus.h"' to 'include"
I would appreciate any suggestions on this one. Thank you very much and have a great day.
Revision history for this message
|
#12 |
Hi,
the issue has been resolved. The problem was that the arm cross compiler was not compiling against the libmodbus library.
Revision history for this message
|
#13 |
Hi JM
I came across you post - I am having exactly the same problems with compiling libmodbus (3.03) using eclipse for the arm?
You mentioned that the problem was that the arm cross compiler was not compiling against the libmodbus library - but never posted you solution on how to solve this problem?
Any help would be much appreciated
regards
John
Revision history for this message
|
#14 |
Dear John,
Its been a long while since I worked with the ARM. That was a
Multitech developer platform. I will try to figure out what solution was it
that I found back then. Meanwhile I posted on Multitech Developer platform
at the time as well. Please go though these posts maybe they would be of
help.
http://
Sorry as right now I do not exactly remember the solution.I hope to find it
and get back to you soon. Take care and good luck.
On Mon, May 27, 2013 at 6:36 PM, JohnMajor <
<email address hidden>> wrote:
> Your question #172535 on libmodbus changed:
> https:/
>
> JohnMajor posted a new comment:
> Hi JM
>
> I came across you post - I am having exactly the same problems with
> compiling libmodbus (3.03) using eclipse for the arm?
>
> You mentioned that the problem was that the arm cross compiler was not
> compiling against the libmodbus library - but never posted you solution on
> how to solve this problem?
> Any help would be much appreciated
> regards
> John
>
> --
> You received this question notification because you asked the question.
>
Revision history for this message
|
#15 |
Much Appreciated John,
I've been racking my brains last few days trying to get this to work?
I am using eclipse indigo platform (on a Ubuntu PC) and have used the
libmodbus (libmodbus-3.0.3) library for compilation on X86 c/c++ projects -
these work OK!
But unfortunately I can't get it to work with the "arm-linux-
compiler I am using.
This arm compiler works fine under normal circumstances but when I use the
libmodus library it throws the following errors:
1. cannot find -lmodbus
2. skipping incompatible /usr/local/
for -lmodbus
Obviously it seems to be finding the libraries in the right place OK but
thinks its incompatible for some reason?
Pretty sure the libraries and include files are located in the right places?
any help would be very much appreciated!
regards
John Major
-----Original Message-----
From: JM
Sent: Tuesday, May 28, 2013 12:56 PM
To: <email address hidden>
Subject: Re: [Question #172535]: Compilation issue
Question #172535 on libmodbus changed:
https:/
JM posted a new comment:
Dear John,
Its been a long while since I worked with the ARM. That was a
Multitech developer platform. I will try to figure out what solution was it
that I found back then. Meanwhile I posted on Multitech Developer platform
at the time as well. Please go though these posts maybe they would be of
help.
http://
Sorry as right now I do not exactly remember the solution.I hope to find it
and get back to you soon. Take care and good luck.
On Mon, May 27, 2013 at 6:36 PM, JohnMajor <
<email address hidden>> wrote:
> Your question #172535 on libmodbus changed:
> https:/
>
> JohnMajor posted a new comment:
> Hi JM
>
> I came across you post - I am having exactly the same problems with
> compiling libmodbus (3.03) using eclipse for the arm?
>
> You mentioned that the problem was that the arm cross compiler was not
> compiling against the libmodbus library - but never posted you solution on
> how to solve this problem?
> Any help would be much appreciated
> regards
> John
>
> --
> You received this question notification because you asked the question.
>
--
You received this question notification because you are a direct
subscriber of the question.
Revision history for this message
|
#16 |
JM
The problem was found to be due to the compiler not linking correctly with
libmodbus library using eclipse running from my X86 based development
desktop pc?
Anyway to solve the issue, I installed libmodbus on an arm-based pc running
ubuntu/linux and then copied all the libmodbus files from the arm based pc
to an special folder on the X86 based development desktop. After setting the
appropriate directory these new files have allow the arm-linux-
compiler to do its job and now accepts the new libmodbus libraries and links
OK
John Major
-----Original Message-----
From: JM
Sent: Tuesday, May 28, 2013 12:56 PM
To: <email address hidden>
Subject: Re: [Question #172535]: Compilation issue
Question #172535 on libmodbus changed:
https:/
JM posted a new comment:
Dear John,
Its been a long while since I worked with the ARM. That was a
Multitech developer platform. I will try to figure out what solution was it
that I found back then. Meanwhile I posted on Multitech Developer platform
at the time as well. Please go though these posts maybe they would be of
help.
http://
Sorry as right now I do not exactly remember the solution.I hope to find it
and get back to you soon. Take care and good luck.
On Mon, May 27, 2013 at 6:36 PM, JohnMajor <
<email address hidden>> wrote:
> Your question #172535 on libmodbus changed:
> https:/
>
> JohnMajor posted a new comment:
> Hi JM
>
> I came across you post - I am having exactly the same problems with
> compiling libmodbus (3.03) using eclipse for the arm?
>
> You mentioned that the problem was that the arm cross compiler was not
> compiling against the libmodbus library - but never posted you solution on
> how to solve this problem?
> Any help would be much appreciated
> regards
> John
>
> --
> You received this question notification because you asked the question.
>
--
You received this question notification because you are a direct
subscriber of the question.
Revision history for this message
|
#17 |
Dear John,
you are perfectly correct. Now when I remember, I faced the
same problem of the complier not having linked with the libmodbus library.
Glad that you found the solution. Thank you for refreshing my memory :)
Take care and Good Luck.
Regards,
JM
On Wed, May 29, 2013 at 8:01 PM, JohnMajor <
<email address hidden>> wrote:
> Your question #172535 on libmodbus changed:
> https:/
>
> JohnMajor posted a new comment:
> JM
> The problem was found to be due to the compiler not linking correctly with
> libmodbus library using eclipse running from my X86 based development
> desktop pc?
> Anyway to solve the issue, I installed libmodbus on an arm-based pc running
> ubuntu/linux and then copied all the libmodbus files from the arm based pc
> to an special folder on the X86 based development desktop. After setting
> the
> appropriate directory these new files have allow the
> arm-linux-
> compiler to do its job and now accepts the new libmodbus libraries and
> links
> OK
> John Major
>
>
> -----Original Message-----
> From: JM
> Sent: Tuesday, May 28, 2013 12:56 PM
> To: <email address hidden>
> Subject: Re: [Question #172535]: Compilation issue
>
> Question #172535 on libmodbus changed:
> https:/
>
> JM posted a new comment:
> Dear John,
> Its been a long while since I worked with the ARM. That was a
> Multitech developer platform. I will try to figure out what solution was it
> that I found back then. Meanwhile I posted on Multitech Developer platform
> at the time as well. Please go though these posts maybe they would be of
> help.
>
> http://
>
> Sorry as right now I do not exactly remember the solution.I hope to find it
> and get back to you soon. Take care and good luck.
>
> Regards,
>
> JM
>
>
> On Mon, May 27, 2013 at 6:36 PM, JohnMajor <
> <email address hidden>> wrote:
>
> > Your question #172535 on libmodbus changed:
> > https:/
> >
> > JohnMajor posted a new comment:
> > Hi JM
> >
> > I came across you post - I am having exactly the same problems with
> > compiling libmodbus (3.03) using eclipse for the arm?
> >
> > You mentioned that the problem was that the arm cross compiler was not
> > compiling against the libmodbus library - but never posted you solution
> on
> > how to solve this problem?
> > Any help would be much appreciated
> > regards
> > John
> >
> > --
> > You received this question notification because you asked the question.
> >
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>
> You received this question notification because you asked the question.
>
Revision history for this message
|
#18 |
Hello guys,
I'm Eclipse Kepler + libmodbus-3.0.4 + gcc x86 user as well and I have problem with test modbus project compilng. I have got
linker errors.
Here source:
#include <modbus/
#include <modbus/modbus.h>
#include "unit-test.h"
int main(void)
{
modbus_t *mb;
uint16_t tab_reg[32];
mb = modbus_
modbus_
/* Read 5 registers from the address 0 */
modbus_
modbus_close(mb);
modbus_free(mb);
while(1);
}
functions headers are presents in modbus.h
libmodbus has installed succed, I tried to compile an example from Tests folder by command line. Executable file has been generated.
What the problem may be please ?
Thank you in advance