News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Can not compile the Paho MQtt libary

Started by mj1234, August 25, 2020, 10:32:14 PM

Previous topic - Next topic

mj1234

Hello,
I am a newbie in Codeblocks. I have a little experience in c programming.
I try to compile the Paho Mqtt libary with codeblocks.
I get the followings Errormessages:
 
"cc -Wall -g -I../../paho.mqtt.c/src/samples -I/home/pi/paho.mqtt.c -I/home/pi/paho.mqtt.c/src/samples -c /home/pi/codeblock-projekt/MJ-Test/pubsub-mj.c -o obj/Debug/pubsub-mj.o
g++  -o bin/Debug/MJ-Test obj/Debug/pubsub-mj.o  -lwiringPi  ../../../../usr/local/lib/libpaho-mqtt3a.so ../../../../usr/local/lib/libpaho-mqtt3as.so ../../../../usr/local/lib/libpaho-mqtt3c.so ../../../../usr/local/lib/libpaho-mqtt3cs.so /usr/local/lib/libpaho-mqtt3a.so /usr/local/lib/libpaho-mqtt3as.so /usr/local/lib/libpaho-mqtt3c.so /usr/local/lib/libpaho-mqtt3cs.so /home/pi/paho.mqtt.c/build/output/libpaho-mqtt3a.so /home/pi/paho.mqtt.c/build/output/libpaho-mqtt3as.so /home/pi/paho.mqtt.c/build/output/libpaho-mqtt3c.so /home/pi/paho.mqtt.c/build/output/libpaho-mqtt3cs.so
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/crt1.o: in function `_start':
(.text+0x34): undefined reference to `main'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) "

I have read so many Internet articles but i can not find a solution.
I do not think that the Code is the problem but the Settings in codeblocks.
I hope everyone can help me.
Maybe it is a simple error for a expert.

Greetings Michael

stahta01

Should the Paho Mqtt libary be a static or dynamic library?
If you do not know try building it as a static library because it is slightly easier.

To change an existing CB Project to an static library:
Project -> Properties
Tab: Build Targets
Select the targets in the left hand list
Change the "type" to static or to dynamic library.
You likely will need to do it for all the targets in the left hand list.

Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

mj1234

Hello Tim,
thank you for your reply.
Unfortunaly the tipp does not work for me. The error mesages disapears but i get the messages "You must select a host application to "run" a libary".
The Paho mqtt programm needs only two files (pubsub_opts.c and pubsub_opts.h).
However, I need a console application.

Regards

Michael


stahta01

Did you write the main function that uses the library?
If not, then do write it.
Write it as a separate target in the project or as a separate project.

Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

mj1234

Ah, i understand.
Thank you for your reply.

Greetings

Michael