Reputation: 23
I am trying to make a C program using libmbus, which I have installed on my raspberry pi. In my /usr/lib directory I have the file libmbus.so and in my /usr/include directory I have the the file ./mbus/mbus.h.
The program looks like this:
#include <stdio.h>
#include <mbus/mbus.h>
int main(void)
{
mbus_handle* MbusHandle;
MbusHandle = mbus_connect_serial("/dev/ttyS1");
return 0;
}
When I try to run "gcc main.cpp -lmbus" I get:
main.cpp:(.text+0xe): undefined reference to `mbus_connect_serial(char const*)'
I tried to run
nm -D /usr/lib/libmbus.so
which among others gives
00009930 T mbus_connect_serial
So it appears that the function mbus_connect_serial is part of libmbus.so.
In the header file the function mbus_connect_serial is defined like this:
mbus_handle * mbus_connect_serial(const char * device);
I can't seem to figure out what is wrong. Can anyone guide me in the right direction?
Upvotes: 1
Views: 1878
Reputation: 14376
If you're really trying to create a c
program, rename main.cpp
to main.c
Upvotes: 2