1

So, my problem is that i have created a .h and a .c file that need to use the hardware/i2c.h and the pico/stdlib.h inside them, but when building the project through cmake the two libraries can't be found.

What am I missing? Thanks a lot

Adding the fullpath to hardware/i2c.h and pico/stdlib.h isn't working because then errors arise inside their includes

The structure is the following:

├── bme68x
│   ├── bme68x_API.h
│   ├── bme68x_API.c
│   ├── ...
│   ├── ...
│   ├── ...
│   └── CMakeLists.txt
├── main.c
├── CMakeLists.c

Inside bme68x_API.c i need to use the two libraries and, while by including them with

#include "hardware/i2c.h"
#include "pico/stdlib.h"

in main.c works, it doens't work in the two files that aren't the main project.

the CMakeLists.txt file is

cmake_minimum_required(VERSION 3.12)

# Pull in SDK (must be before project)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

project(forced_mode C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
    message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

# Initialize the SDK
pico_sdk_init()

add_subdirectory(bme68x)

add_executable(${PROJECT_NAME}
    main.c
    )

# pull in common dependencies
target_link_libraries(${PROJECT_NAME} 
    pico_stdlib
    hardware_i2c
    bme68x
)


#enable usb output
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(${PROJECT_NAME})

While the bme68x/CMakeLists.txt file is simply

add_library(
    bme68x
    bme68x_defs.h
    bme68x.h
    bme68x.c
    bme68x_API.h
    bme68x_API.c
)

1 Answers1

1

Just add

target_link_libraries( bme68x hardware_i2c pico_stdlib)

inside the bme68x/CMakeLists.txt and it works, so libraries need to be called inside each make