C++ Libraries

I just got a Inky Impression 4" and I’m having issues using the C++ libraries. The examples all seem to compile and run fine, but when I try to build my own project it can’t find many of the libraries to link against. Specifically inky_frame.a fatfs.a and a few others seem to be missing. Looking at the CMake outputs, it looks like it’s never even trying to build any of those libraries. I’m lost as to how the examples are running and mine isn’t. Here’s my CMakeLists.txt.

cmake_minimum_required(VERSION 3.12)

set(NAME          rp2040_test)
set(PICO_PLATFORM rp2040)
set(PICO_BOARD    pico_w)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
#include(pico_extras_import_optional.cmake)
include(pimoroni_pico_import.cmake)

project(${NAME} C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

set(PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS 3000)

link_directories(${PIMORONI_PICO_PATH}/build/)
link_directories(${PIMORONI_PICO_PATH}/build/libraries/pico_graphics)
link_directories(${PIMORONI_PICO_PATH}/build/libraries/jpegdec)
link_directories(${PIMORONI_PICO_PATH}/build/libraries/inky_frame)

add_executable(${NAME}
               rp2040_test.cpp)

target_link_libraries(rp2040_test
		      pico_stdlib
		      jpegdec
		      hardware_pwm
		      hardware_spi
		      hardware_i2c
		      hardware_rtc
		      pico_graphics
		      inky_frame)

# enable usb output, disable uart output
pico_enable_stdio_usb(${NAME} 1)
pico_enable_stdio_uart(${NAME} 0)

Are you sure you have an Inky Impression? That device is not for the Pico, it is for the Pi.

Otherwise, your CMakeLists.txt seems almost ok. The fatfs is not in the “target_link_libraries”.

You can compare to one of my examples that use a library: pico-bme688-scan/CMakeLists.txt at main · bablokb/pico-bme688-scan · GitHub. As you can see, I have a “add_subdirectory” statement and not a “link_directories”-statement. You would have to dig through the CMake documentation to see if this makes a difference.

Yeah, I have an Inky Frame…not sure why I said Impression. When I build the Pimoroni libraries, should there be .a files for inky_frame and fanfs? I also forgot to mention that I’m doing this on Ubuntu 24.04.

CMake will take care of all that for you, once you have your CMakeLists.txt right; those link_directories look odd - or at least, not in step with the boilerplate, which is always a good place to start from because getting things to build and link properly is, as you’re finding out, a bit of a dark art :-)

Ok. Got it working. I had started with the boilerplate and cmake was complaining about the include statements which is why I was trying to just hard-link to the .a files. It seems like in the boilerplate file the include command doesn’t include the .cmake extension and that was causing it to fail. If it put the extension in, everything worked. Not sure why my setup was complaining about that, but if it works I’m not going to complain.

Ahh yes, I’ve always found that too - not sure if it’s a CMake version thing or just a bug in the boilerplate :-)