I have been learning to write drivers for a Pi Pico and I implemented my own GPIO library.
But I am unable to get it to build as the linker is not able to find the library (-lcustom_gpio).
This is how my project directory looks.
.
└── LED_Blink/
├── build
├── gpio/
│ ├── CMakeLists.txt
│ ├── gpio.cpp
│ └── gpio.hpp
├── CMakeLists.txt
├── main.cpp
├── main.hpp
└── pico_sdk_import.cmake
CmakeLists.txt under gpio:
set(gpio_files gpio.cpp gpio.hpp)
add_library(custom_gpio ${gpio_files})
CMakeLists.txt under root:
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(test_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
set(SOURCE_FILES main.cpp)
add_executable(test
${SOURCE_FILES}
)
target_link_libraries(test custom_gpio)
target_include_directories(test ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gpio)
pico_add_extra_outputs(test custom_gpio)
Output of 'cmake ..':
PICO_SDK_PATH is /home/arun/pico/pico-sdk
PICO platform is rp2040.
Build type is Release
PICO target board is pico.
Using board configuration from /home/arun/pico/pico-sdk/src/boards/include/boards/pico.h
TinyUSB available at /home/arun/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
BTstack available at /home/arun/pico/pico-sdk/lib/btstack
cyw43-driver available at /home/arun/pico/pico-sdk/lib/cyw43-driver
Pico W Bluetooth build support available.
lwIP available at /home/arun/pico/pico-sdk/lib/lwip
mbedtls available at /home/arun/pico/pico-sdk/lib/mbedtls
-- Configuring done
-- Generating done
-- Build files have been written to: /home/arun/pico/LED_Blink/build
output of 'make -j4':
Scanning dependencies of target bs2_default
[ 5%] Performing build step for 'ELF2UF2Build'
[ 10%] Performing build step for 'PioasmBuild'
[ 20%] Built target bs2_default
[100%] Built target elf2uf2
[100%] Built target pioasm
[ 25%] No install step for 'ELF2UF2Build'
[ 30%] No install step for 'PioasmBuild'
[ 35%] Completed 'ELF2UF2Build'
[ 40%] Completed 'PioasmBuild'
[ 65%] Built target ELF2UF2Build
[ 90%] Built target PioasmBuild
Consolidate compiler generated dependencies of target test
[ 95%] Linking CXX executable test.elf
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: cannot find -lcustom_gpio: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:97: test.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1490: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I have been referring to related StackOverflow threads and CMake documentation, but I am stuck getting this project to build.
What am I doing wrong?