So, it turns out that compiling C applications requires a little bit of know-how. Here are some pointers to help young players.
To get some compiler settings, give this a whirl:
cpp -v /dev/null -o /dev/null
gcc -L . -o mqtt_a_sub paho_c_sub.c
paho_c_sub.c:45:19: error: mysql.h: No such file or directory
This error is the compiler complaining that it can’t find the header file mysql.h
. After installing the mysql-devel
package, and a quick search for the header file (found in /usr/include/mysql
), the gcc compiler can be pointed at the include directory using the -I
directive.
gcc -I/usr/include/mysql -o mqtt_a_sub paho_c_sub.c
/tmp/ccaoViZJ.o: In function `messageArrived':
paho_c_sub.c:(.text+0x5b4): undefined reference to `MQTTAsync_freeMessage'
paho_c_sub.c:(.text+0x5c0): undefined reference to `MQTTAsync_free'
/tmp/ccaoViZJ.o: In function `onConnect':
paho_c_sub.c:(.text+0x732): undefined reference to `MQTTAsync_subscribe'
/tmp/ccaoViZJ.o: In function `connectionLost':
paho_c_sub.c:(.text+0x796): undefined reference to `MQTTAsync_connect'
/tmp/ccaoViZJ.o: In function `main':
paho_c_sub.c:(.text+0x906): undefined reference to `MQTTAsync_create'
paho_c_sub.c:(.text+0x92c): undefined reference to `MQTTAsync_setCallbacks'
paho_c_sub.c:(.text+0x9ae): undefined reference to `MQTTAsync_connect'
paho_c_sub.c:(.text+0xa2d): undefined reference to `MQTTAsync_disconnect'
paho_c_sub.c:(.text+0xa7a): undefined reference to `MQTTAsync_destroy'
collect2: ld returned 1 exit status
This little pearler is due to the MQTT library not being linked. This can be remedied by using the -l
directive to explicitly specify the library name when linking.
gcc -L . -o mqtt_a_sub paho_c_sub.c -lpaho-mqtt3a