Install mqtt client libraries on raspberry pi - c

I've been trying to compile the Paho MQTT client libraries on raspbian buster. Cloned the github source:
git clone https://github.com/eclipse/paho.mqtt.c.git
As per the README file I've run make (OK except for 1 warning that 'rc1 not used') then sudo make install which happily copies sundry MQTTxx.h and MQTTxx.c files into the /usr/include directory.
However, attempts to compile a Paho demo program results in:
richard#grigio:[~]: gcc mqtest.c
/tmp/ccvjYcVw.o: In function `main':
mqtest.c:(.text+0x68): undefined reference to `MQTTClient_create'
mqtest.c:(.text+0x8c): undefined reference to `MQTTClient_connect'
mqtest.c:(.text+0xe4): undefined reference to `MQTTClient_publishMessage'
mqtest.c:(.text+0x114): undefined reference to `MQTTClient_waitForCompletion'
mqtest.c:(.text+0x138): undefined reference to `MQTTClient_disconnect'
mqtest.c:(.text+0x144): undefined reference to `MQTTClient_destroy'
collect2: error: ld returned 1 exit status
so I thought I needed to link the library:
richard#grigio:[~]: gcc mqtest.c -lMQTTClient
/usr/bin/ld: cannot find -lMQTTClient
collect2: error: ld returned 1 exit status
MQTTClient.h and MQTTClient.c are present in /usr/include so what am I doing wrong, please?

Related

Issue with linking libraries built with gnat

When trying to build some test cases (just programs written in Ada), I get the following error:
gcc -c -shared decimaltests.adb
gnatbind -x decimaltests.ali
gnatlink decimaltests.ali -lGenerics -lNumerics -lTesting
/usr/bin/ld: decimaltests: hidden symbol `_Unwind_Resume' in
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/libgcc_eh.a(unwind-dw2.o) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
gnatlink: error when calling /usr/bin/gcc
gnatmake: *** link failed.
I'm building them with gnatmake -shared *.ad{b,s} -largs -lGenerics -lNumerics -lTesting Clearly this isn't a problem with building the sources, but just to further confirm that, I copied the sources into this directory and built using gnatmake -shared *.ad{b,s} which built the tests just fine.
The dependent libraries are built and installed into a path gnat searches through. It doesn't seem to be an issue of not finding those. Not sure what's going on here.
All the libraries are built with gnatmake -O2 -fPIC -shared *.ad{b,s} as well as any relevant library dependencies. All libraries that depend on these can still be built. It's only even programs that depend on the libraries that throw this error, and always the same error.
Update: Building the libraries using gprbuild and then installing them with gprinstall seems to work similarly, except now the error is as follows:
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x43): undefined reference to `testing__start'
decimaltests.adb:(.text+0x4a): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x9e): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x108): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x172): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x1dc): undefined reference to
`generics__testing__default_tolerance'
decimaltests.o:decimaltests.adb:(.text+0x23f): more undefined references to
`generics__testing__default_tolerance' follow
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x14f5): undefined reference to `testing__stop'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__not_started#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__pass#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__fail#SYMS'
collect2: error: ld returned 1 exit status
gprbuild: link of decimaltests.adb failed
So I looked through the symbols table for both build methods and noticed, in both cases, the symbol most definitely exists, but the reference to it seems to be the wrong location. I'll try building on different platforms/compilers and update again if anything relevant comes up.
Both processes correctly build the libraries and test programs, and the test programs run properly, on different platforms. To further confirm that this is a bug, I've installed a different GCC toolchain and repeated the builds under the original platform, and this problem did not arise. I'll be filing a bug report.

Trying to use libcurl in my program and getting "undefined reference" errors

I am getting the following errors:
/tmp/ccno287V.o: In function `download_feed':
feedObtain.c:(.text+0xb9): undefined reference to `curl_easy_init'
feedObtain.c:(.text+0xde): undefined reference to `curl_easy_setopt'
feedObtain.c:(.text+0xff): undefined reference to `curl_easy_setopt'
feedObtain.c:(.text+0x10b): undefined reference to `curl_easy_perform'
collect2: error: ld returned 1 exit status
Command used to get libcurl:
apt-get install libcurl4-gnut
Your program is not linked with the libcurl library and hence the linker complains that it could resolve symbols. Link the library with:
cc feedObtain.c -lcurl
Note that the library must be specified at the end of the commandline options.

Undefined references everywhere, while trying to compile BluezTools?

I'm trying to compile BluezTools using the following command:
./autogen.sh && ./configure && make
Here is a snippet of the output:
obextransfer.c:(.text+0x4d5): undefined reference to `g_type_check_instance_cast'
obextransfer.c:(.text+0x4f1): undefined reference to `dbus_g_proxy_disconnect_signal'
obextransfer.c:(.text+0x4fd): undefined reference to `g_object_unref'
obextransfer.c:(.text+0x50a): undefined reference to `g_free'
obextransfer.c:(.text+0x517): undefined reference to `g_object_unref'
obextransfer.c:(.text+0x528): undefined reference to `g_type_check_class_cast'
lib/obexd/obextransfer.o: In function `obextransfer_cancel':
obextransfer.c:(.text+0x56a): undefined reference to `g_type_check_instance_is_a'
obextransfer.c:(.text+0x58a): undefined reference to `g_assertion_message_expr'
lib/obexd/obextransfer.o: In function `obextransfer_get_dbus_object_path':
obextransfer.c:(.text+0x5e2): undefined reference to `g_type_check_instance_is_a'
obextransfer.c:(.text+0x602): undefined reference to `g_assertion_message_expr'
lib/obexd/obextransfer.o: In function `_obextransfer_get_property':
obextransfer.c:(.text+0x64f): undefined reference to `g_type_check_instance_cast'
obextransfer.c:(.text+0x660): undefined reference to `g_type_name'
obextransfer.c:(.text+0x66f): undefined reference to `g_type_name'
obextransfer.c:(.text+0x6a3): undefined reference to `g_log'
lib/obexd/obextransfer.o: In function `progress_handler':
obextransfer.c:(.text+0x4af): undefined reference to `g_signal_emit'
lib/obexd/obextransfer.o: In function `obextransfer_cancel':
obextransfer.c:(.text+0x5ad): undefined reference to `dbus_g_proxy_call'
lib/obexd/obextransfer.o: In function `obextransfer_get_dbus_object_path':
obextransfer.c:(.text+0x619): undefined reference to `dbus_g_proxy_get_path'
lib/obexd/obextransfer.o: In function `_obextransfer_get_property':
obextransfer.c:(.text+0x6e7): undefined reference to `g_value_set_string'
collect2: error: ld returned 1 exit status
make[2]: *** [bt-monitor] Error 1
make[2]: Leaving directory `/home/[]/Downloads/bluez-tools-bluez-tools/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/[]/Downloads/bluez-tools-bluez-tools
This is my first attempt as building a C project on Linux, where am I going wrong?
Running Linux Mint 15 Olivia 64bit.
Do you have bluez and obexd installed? https://code.google.com/p/bluez-tools/#Requirements
You could check the output of ./configure for any errors. Usually there is a configure.log or similar to grep for erros.
I dont know about Mint package management, but you probably need some kind of obex*-dev package at least or install obex source yourself.
EDIT Edited to answer the comment.
I do not think the obexd-client is enough, but try this method and see if it is. Otherwise you need to look for some -dev packages like libglib2.0-cil-dev libglib2.0-dev and libdbus-glib-1-dev. (Those are the names on Ubuntu).
Here is how I got it to compile (still emits warnings, though).
Install a bunch of -dev packages for glib and dbus (ddg/google the functions that fail to link, so you see which libraries they are from).
Execute pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0
Use the output of the command in the ./configure e.g.:
env LIBS="-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0" ./configure
Execute make
See also this question: Compilation error dbus-ping-pong
Fixed a similar problem by adding pkg-config --libs gtk+-2.0. Maybe helps someone.

Which library shall I add to get fcntl64, stat64, ... resolved?

I'm trying to build a project for ARM uClibc environment, but I've some functions missing. Can not find which library shall I include to resolve dependancies. nm do not help me to search, since it says on most of libs coming with toolchain:
nm: ./host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/libuClibc-0.9.32.1.so: no symbols
Here is the output from GCC:
./host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc
-Wl,-rpath,./host/usr/lib/
-Wl,-rpath,./host/usr/../lib/
-Wl,-rpath,./host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/
-Llibzway -o test_so main.o -lzway
-L./host/usr/lib/
-L./host/usr/../lib/
-L./host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/ -lpthread
-lxml2 -lz -lm
./host/usr/lib/libxml2.so: warning: gethostbyname is obsolescent, use getnameinfo() instead.
./host/usr/lib/libxml2.so: undefined reference to `fcntl64'
./host/usr/lib/libxml2.so: undefined reference to `fopen64'
./host/usr/../lib/libz.so: undefined reference to `lseek64'
./host/usr/lib/libxml2.so: undefined reference to `stat64'
./host/usr/lib/libiconv.so.2: undefined reference to `mbrtowc'
./host/usr/lib/libiconv.so.2: undefined reference to `_stdlib_mb_cur_max'
./host/usr/lib/libiconv.so.2: undefined reference to `wcrtomb'
./host/usr/lib/libxml2.so: undefined reference to `open64'
collect2: ld returned 1 exit status
make: *** [test_so] Error 1
UPD:
I've copied uClibc from the target host and explicitely defined asked to link with it:
./host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc
-Wl,-rpath,./host/usr/lib/
-Wl,-rpath,./host/usr/../lib/
-Wl,-rpath,./host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/
-Llibzway -o test_so main.o -lzway
-L./host/usr/lib/
-L./host/usr/../lib/
-L./host/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/
-luClibc-0.9.31
-lpthread -lxml2 -lz -lm
./host/usr/bin/../lib/gcc/arm-unknown-linux-uclibcgnueabi/4.5.3/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld:
errno: TLS reference in ./host/usr/bin/../arm-unknown-linux-uclibcgnueabi/sysroot/lib/libpthread.so.0 mismatches non-TLS definition in ./host/usr/lib/libuClibc-0.9.31.so section .bss
./host/usr/bin/../arm-unknown-linux-uclibcgnueabi/sysroot/lib/libpthread.so.0: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [test_so] Error 1
This is much bayond my knowledge of cross-compilation. Any idea?
It sounds like you have several issues going on:
You seem to be trying to use the host's copy of libxml2.so. This is not going to work. You need one built for your target system and its libc.
Your uClibc was compiled without large file support. Go back and fix the build options or uClibc. It's not strictly necessary (a correctly built libxml2.so linked against uClibc will work without doing this), but using the pre-large-file interfaces is really backwards and will unnecessarily limit your programs.

undefined reference to #include <iconv.h>,`libiconv_open',`libiconv',`libiconv_close'

I had a problem with adding reference in my C application. I am unable to add linker reference to "libiconv" in my data compresser project.I have download "libiconv" library but confuse in adding reference which show error in compiling.I'm using Dev C++ for developing my compression apps.
here is the compile log:
Building Makefile: "C:\Dev-Cpp\Examples\eottest\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Examples\eottest\Makefile.win" all
gcc.exe eot.o libeot.o properties.o -o "Project1.exe" -L"C:/Dev-Cpp/lib"
libeot.o(.text+0x19):libeot.c: undefined reference to `libiconv_open'
libeot.o(.text+0x36):libeot.c: undefined reference to `libiconv_close'
libeot.o(.text+0x67):libeot.c: undefined reference to `libiconv'
collect2: ld returned 1 exit status`
You're only specifying an additional library path, not the actual library to link to. Try:
gcc.exe eot.o libeot.o properties.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" -liconv

Resources