Author Topic: Can not compile the Paho MQtt libary  (Read 3748 times)

Offline mj1234

  • Single posting newcomer
  • *
  • Posts: 3
Can not compile the Paho MQtt libary
« on: August 25, 2020, 10:32:14 pm »
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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Can not compile the Paho MQtt libary
« Reply #1 on: August 25, 2020, 11:18:25 pm »
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++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mj1234

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can not compile the Paho MQtt libary
« Reply #2 on: August 26, 2020, 11:03:08 pm »
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


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Can not compile the Paho MQtt libary
« Reply #3 on: August 26, 2020, 11:14:24 pm »
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++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mj1234

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can not compile the Paho MQtt libary
« Reply #4 on: August 29, 2020, 08:57:20 pm »
Ah, i understand.
Thank you for your reply.

Greetings

Michael