Do you need to link a demo in a custom project?

If I am making a custom project do I still need to link a demo in my root CMakeLists.txt? For example if I take the following line out,

target_link_libraries(esp32_app PRIVATE AFR::demo_mqtt)

I get linking errors like:

../amazon-freertos-configs/iot_config.h:76:31: fatal error: iot_config_common.h: No such file or directory

and the following files also don’t link.

#include "bt_hal_manager.h"
#include "iot_system_init.h"
#include "iot_logging_task.h"

The AFR::demo_mqtt target defines the demo source files, header files, and dependencies required to run the MQTT demo application. If you’re writing your own application and not using the MQTT demo source files, then you don’t need to link to this target.

If you are creating your own application, then you will need to add dependencies to your targets as required. For example, if your application uses the MQTT library, then you will need to add a dependency on the AFR::mqtt target.

1 Like

Ya that makes sense, however I am not able to get it to work correctly. Perhaps I’m missing something. For example,

In my main CMakeList.txt if I change

target_link_libraries(esp32_app PRIVATE AFR::demo_mqtt)


target_link_libraries(esp32_app PRIVATE AFR::mqtt)

then in my main.c, the following files don’t get linked

#include "iot_system_init.h"
#include "aws_dev_mode_key_provisioning.h"

which are required for the following lines:

    if( SYSTEM_Init() == pdPASS )
        /* A simple example to demonstrate key and certificate provisioning in
         * microcontroller flash using PKCS#11 interface. This should be replaced
         * by production ready key provisioning mechanism. */

So what’s the best way to add the correct dependencies? Thanks!


target_link_libraries(esp32_app PRIVATE AFR::mqtt)

is the only library being linked in my main CMakeList.txt

The code you referenced seems to be from the demo. If this is the case, you will need to add the dependencies required by the demo. You can do this with your current code:
target_link_libraries(esp32_app PRIVATE AFR::demo_mqtt)

Here is some additional information if you’re not planning on using the demo.

The code related to AFR is organized into a number of different targets. Each target represents a grouping of code (typically a library) and defines things required for building such as source code, include paths, compiler options, and a list of other targets that it depends on. As you have seen previously, the library targets are identified by names such as AFR::mqtt.

Dependencies added with target_link_libraries are transitive. For example, if you have
target_link_libraries(A PRIVATE AFR::ota), then you can also use mqtt in A because OTA depends on mqtt.

You can see a list of some of the available libraries here:

You can see how to add these libraries to your project in the following documentation:

Yes I understand that, but isn’t the following line of code something that should be implemented without a demo linked?

    if( SYSTEM_Init() == pdPASS )


1 Like

That function is defined in the AFR::utils target.

It can be linked to with:
target_link_libraries(esp32_app PRIVATE AFR::utils)

1 Like