Cross-compilling code with pahomqttc headers

Hi all,
I'm trying to compile a simple C code with libpahomqttc headers to run on an openwrt-box. I've managed to build and install the libraries on my host OS (debian-64bits) following the tutorial at the eclipse page. I've followed the openwrt tutorial for custom packages and compiled the hellloworld successfully. Now I'm trying to compile my code but i'm finding some cross-compilation issues. I made some research on the wiki but didn't find anything that could help me.

home/joao/src/build_dir/target-mips_24kc_musl/pahocap-1.0/pahocap.c:4:10: fatal error: MQTTClient.h: No such file or directory
 #include "MQTTClient.h"
          ^~~~~~~~~~~~~~
compilation terminated.

Should I try to add the .so files I have built to the toolchain? or simpling linking them with some flags on my makefile? I'm not really familiar with cross-compilling so I could use a hand.

Here's my make file, i've tried some stuff with Build/InstallDev

#
# Copyright (C) 2006-2018 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=pahocode
PKG_VERSION:=1.0
PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/path/to/pahocode

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/pahocode
	SECTION:=examples
	CATEGORY:=Examples
	TITLE:=pahocode
	DEPENDS:=+libpthread +libopenssl +libpcap
endef


# Package description; a more verbose description on what our package does
define Package/pahocode/description
	A simple application to send data a remote mqtt broker using pahomqttc codes
endef

# Package preparation instructions; create the build directory and copy the source code. 
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -r $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
	$(Build/Patch)
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include
	$(CP) $(SOURCE_DIR)/headers/MQTT*.h $(1)/usr/include/
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(SOURCE_DIR)/so/libpaho-mqtt3*.so* $(1)/usr/lib/	
endef

# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
	$(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/pahocode.o -c $(PKG_BUILD_DIR)/pahocode.c -L/home/joao/paho.mqtt.c/build/output -lpahomqttc
	$(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/pahocode.o -L/home/joao/paho.mqtt.c/build/output -lpahomqttc
endef

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/pahocode/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/$(PKG_NAME).so.* $(1)/usr/lib/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/pahocode $(1)/usr/bin
endef

# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,pahocode))

I've copied the headers and libraries from pahomqttc source to my codedir to try add to the compilation.

I've made some progress on my own, I've found a port here and add a dependency from his library to my Makefile and got the compiler to understand the include. Now the toolchain error changed to

/src/build_dir/target-mips_24kc_musl/pahocode-1.0/pahocap.o: In function `main':
pahocode.c:(.text.startup+0xa): undefined reference to `pcap_lookupdev'
pahocode.c:(.text.startup+0x48): undefined reference to `MQTTClient_create'
pahocode.c:(.text.startup+0x58): undefined reference to `MQTTClient_connect'
pahocod.c:(.text.startup+0x82): undefined reference to `MQTTClient_publishMessage'
pahocode.c:(.text.startup+0x9e): undefined reference to `MQTTClient_waitForCompletion'
pahocode.c:(.text.startup+0xb2): undefined reference to `MQTTClient_disconnect'
pahocode.c:(.text.startup+0xb8): undefined reference to `MQTTClient_destroy'
collect2: error: ld returned 1 exit status

As long as the code runs normally on my local machine should I add different include calls for the toolchain?

here's the c code for reference

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "MQTTClient.h"
#include "pcap.h"

#define ADDRESS     "iot.eclipse.org"
#define CLIENTID    "ExampleClientPub"
#define TOPIC       "mytopic"
#define PAYLOAD     "Hello World!"
#define QOS         1
#define TIMEOUT     10000L

int main(int argc, char* argv[])
{
	char *dev, errbuf[PCAP_ERRBUF_SIZE];

		dev = pcap_lookupdev(errbuf);
		if (dev == NULL) {
			fprintf(stderr, "Couldn't find default device: %s\n", errbuf);

		}
		printf("Device: %s\n", dev);

    MQTTClient client;
    MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
    MQTTClient_message pubmsg = MQTTClient_message_initializer;
    MQTTClient_deliveryToken token;
    int rc;

    MQTTClient_create(&client, ADDRESS, CLIENTID,
        MQTTCLIENT_PERSISTENCE_NONE, NULL);
    conn_opts.keepAliveInterval = 20;
    conn_opts.cleansession = 1;

    if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
    {
        printf("Failed to connect, return code %d\n", rc);
        exit(-1);
    }
    pubmsg.payload = PAYLOAD;
    pubmsg.payloadlen = strlen(PAYLOAD);
    pubmsg.qos = QOS;
    pubmsg.retained = 0;
    MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);
    printf("Waiting for up to %d seconds for publication of %s\n"
            "on topic %s for client with ClientID: %s\n",
            (int)(TIMEOUT/1000), PAYLOAD, TOPIC, CLIENTID);
    rc = MQTTClient_waitForCompletion(client, token, TIMEOUT);
    printf("Message with delivery token %d delivered\n", token);
    MQTTClient_disconnect(client, 10000);
    MQTTClient_destroy(&client);
    return rc;
}

See also, from today

A package is the most robust way to build code for OpenWrt. Even if you're able to cross-compile outside of the build system, you may end up with an incompatible libc, or other libraries. (You'll find, like in many embedded projects, that even if the call is present, it may not work as expected, such as printf())

A package is the most robust way to build code for OpenWrt. Even if you're able to cross-compile outside of the build system, you may end up with an incompatible libc, or other libraries. (You'll find, like in many embedded projects, that even if the call is present, it may not work as expected, such as printf() )

I ran exactly into this, after adding the -l flags I obtained mypackage.ipkg file but the code didn't run as I expected to.

Thanks for the reply @jeff, any new suggestions on what I should be looking next ?