Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8035

SDK • Re: project can't find my library source files in subdirectory (cmake issues?)

$
0
0
First, thanks to those who have responded. dthacher, I did not quite get your source code yet. Why so many compile flags?

Well, the tutorial didn't help. My library source code can't find the Pico SDK functions. I've been trying to add status messages and such using get_property and cmake_print_variables after include(CMakePrintHelpers) but still no luck.

I don't understand why the path to the SDK functions work for the pico/examples but not for my project. I seem to be doing the same thing, but I guess not. What's up with this CMake build system, it is crazy.

Soooo, why can't it find the path to the SDK now? Hmm.

Did I break it by adding a target_include_directories() command to my example file?!

full directory and file listing except build, which I deleted. dirs have slashes behind them

Code:

breaker@ace:~/pico$ ls -R tmp117tmp117:1_temp_result/  2_alerts/  3_set_offset/  CMakeLists.txt  pico_sdk_import.cmake  src/  tmp117_examples.txttmp117/1_temp_result:CMakeLists.txt  temp_result.ctmp117/2_alerts:CMakeLists.txt  alerts.ctmp117/3_set_offset:CMakeLists.txt  set_offset.ctmp117/src:CMakeLists.txt  tmp117.c  tmp117.h  tmp117_registers.h
/tmp117/CMakeLists.txt

Code:

# Minimum required CMake versioncmake_minimum_required(VERSION 3.21)# Pull in SDK (must be before project)include(pico_sdk_import.cmake)include(CMakePrintHelpers)project(tmp117_examples 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 SDKpico_sdk_init()# Add the src directory to include directories# include_directories(${PROJECT_SOURCE_DIR}/src)# message(STATUS "Include Directories: ${CMAKE_INCLUDE_PATH}")add_compile_options(        -Wall                # Enable most warning messages        -Wno-format          # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int        -Wno-unused-function # we have some for the docs that aren't called        )if (CMAKE_C_COMPILER_ID STREQUAL "GNU")   add_compile_options(-Wno-maybe-uninitialized)endif()# Add the src directory to the buildadd_subdirectory(src)# Add example subdirectoriesadd_subdirectory(1_temp_result)add_subdirectory(2_alerts)add_subdirectory(3_set_offset)message(STATUS "root")message(STATUS "Pico SDK path: ${PICO_SDK_PATH}")get_property(dirs3 DIRECTORY PROPERTY INCLUDE_DIRECTORIES)get_property(dirs3 DIRECTORY src PROPERTY INCLUDE_DIRECTORIES)get_property(dirs3 DIRECTORY 1_temp_result PROPERTY INCLUDE_DIRECTORIES)foreach(dir ${dirs3})  message(STATUS "dir=${dir}")endforeach()cmake_print_variables(PROJECT_SOURCE_DIR PROJECT_BINARY_DIR)cmake_print_variables(CMAKE_INCLUDE_PATH)
/tmp117/src/CMakeLists.txt

Code:

# CMakeLists.txt in the src directory# Define a library named 'tmp117_functions'add_library(tmp117_functions    tmp117.c)
This is for the example code
/tmp117/1_temp_result/CMakeLists.txt

Code:

add_executable(temp_result        temp_result.c        )# target_compile_definitions(temp_result PRIVATE PICO_DEFAULT_I2C=0)# pull in common dependencies and additional i2c hardware supporttarget_link_libraries(temp_result PUBLIC tmp117_functions pico_stdlib hardware_i2c pico_printf)# add tmp117_functions library to target's include directoriestarget_include_directories      (temp_result PUBLIC                                 ${PROJECT_BINARY_DIR}                                 ${PROJECT_SOURCE_DIR}/src                                )# enable usb output, disable uart output# pico_enable_stdio_usb(temp_result 1)# pico_enable_stdio_uart(temp_result 0)# create map/bin/hex file etc.pico_add_extra_outputs(temp_result)# add url via pico_set_program_url# example_auto_set_url(temp_result)message(STATUS "1_temp_result")get_property(dirs1 TARGET temp_result PROPERTY INCLUDE_DIRECTORIES)get_property(dirs2 TARGET temp_result PROPERTY INTERFACE_INCLUDE_DIRECTORIES)foreach(dir ${dirs2})  message(STATUS "Interface include directory for temp_result: ${dir}")endforeach()get_property(dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)foreach(dir ${dirs})  message(STATUS "dir='${dir}'")endforeach()cmake_print_variables(CMAKE_INCLUDE_PATH)
So, I run cmake and get this output

Code:

breaker@ace:~/pico/tmp117/build$ cd .. && rm -R build && mkdir build && cd build && cmake ..Using PICO_SDK_PATH from environment ('/usr/src/pico-sdk')PICO_SDK_PATH is /usr/src/pico-sdkDefaulting PICO_PLATFORM to rp2040 since not specified.Defaulting PICO platform compiler to pico_arm_gcc since not specified.-- Defaulting build type to 'Release' since not specified.PICO compiler is pico_arm_gcc-- The C compiler identification is GNU 13.2.1-- The CXX compiler identification is GNU 13.2.1-- The ASM compiler identification is GNU-- Found assembler: /usr/src/arm-gnu-toolchain/bin/arm-none-eabi-gcc-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Check for working C compiler: /usr/src/arm-gnu-toolchain/bin/arm-none-eabi-gcc - skipped-- Detecting C compile features-- Detecting C compile features - done-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - done-- Check for working CXX compiler: /usr/src/arm-gnu-toolchain/bin/arm-none-eabi-g++ - skipped-- Detecting CXX compile features-- Detecting CXX compile features - doneBuild type is ReleaseDefaulting PICO target board to pico since not specified.Using board configuration from /usr/src/pico-sdk/src/boards/include/boards/pico.h-- Found Python3: /usr/bin/python3.9 (found version "3.9.18") found components: Interpreter TinyUSB available at /usr/src/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.BTstack available at /usr/src/pico-sdk/lib/btstackcyw43-driver available at /usr/src/pico-sdk/lib/cyw43-driverPico W Bluetooth build support available.lwIP available at /usr/src/pico-sdk/lib/lwipmbedtls available at /usr/src/pico-sdk/lib/mbedtls-- 1_temp_result-- Interface include directory for temp_result: /home/breaker/pico/tmp117/build-- Interface include directory for temp_result: /home/breaker/pico/tmp117/src-- CMAKE_INCLUDE_PATH=""-- root-- Pico SDK path: /usr/src/pico-sdk-- PROJECT_SOURCE_DIR="/home/breaker/pico/tmp117" ; PROJECT_BINARY_DIR="/home/breaker/pico/tmp117/build"-- CMAKE_INCLUDE_PATH=""-- Configuring done-- Generating done-- Build files have been written to: /home/breaker/pico/tmp117/build
Now to make the example

Code:

breaker@ace:~/pico/tmp117/build$ cd 1_temp_result && make[  2%] Creating directories for 'ELF2UF2Build'[  5%] No download step for 'ELF2UF2Build'[  5%] No update step for 'ELF2UF2Build'[  8%] No patch step for 'ELF2UF2Build'[  8%] Performing configure step for 'ELF2UF2Build'-- The C compiler identification is GNU 11.2.0-- The CXX compiler identification is GNU 11.2.0-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Check for working C compiler: /usr/bin/cc - skipped-- Detecting C compile features-- Detecting C compile features - done-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - done-- Check for working CXX compiler: /usr/bin/c++ - skipped-- Detecting CXX compile features-- Detecting CXX compile features - done-- Configuring done-- Generating done-- Build files have been written to: /home/breaker/pico/tmp117/build/elf2uf2[ 10%] Performing build step for 'ELF2UF2Build'[ 50%] Building CXX object CMakeFiles/elf2uf2.dir/main.cpp.o[100%] Linking CXX executable elf2uf2[100%] Built target elf2uf2[ 10%] No install step for 'ELF2UF2Build'[ 10%] Completed 'ELF2UF2Build'[ 10%] Built target ELF2UF2BuildScanning dependencies of target bs2_default[ 10%] Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj[ 13%] Linking ASM executable bs2_default.elf[ 13%] Built target bs2_default[ 16%] Generating bs2_default.bin[ 18%] Generating bs2_default_padded_checksummed.S[ 18%] Built target bs2_default_padded_checksummed_asm[ 21%] Building C object src/CMakeFiles/tmp117_functions.dir/tmp117.c.obj/home/breaker/pico/tmp117/src/tmp117.c:5:10: fatal error: hardware/i2c.h: No such file or directory    5 | #include "hardware/i2c.h"      |          ^~~~~~~~~~~~~~~~compilation terminated.make[2]: *** [src/CMakeFiles/tmp117_functions.dir/build.make:76: src/CMakeFiles/tmp117_functions.dir/tmp117.c.obj] Error 1make[1]: *** [CMakeFiles/Makefile2:1708: src/CMakeFiles/tmp117_functions.dir/all] Error 2make: *** [Makefile:91: all] Error 2
Code snippet from the above referenced /home/breaker/pico/tmp117/src/tmp117.c

Code:

// tmp117.c#include "tmp117.h"#include "tmp117_registers.h"#include "hardware/i2c.h"#include "pico/printf.h"#include "pico/stdlib.h"#include "pico.h"
Time to go hiking instead, too much useless CMake tutorials and fruitless hours spent.

Statistics: Posted by breaker — Thu Feb 22, 2024 6:48 am



Viewing all articles
Browse latest Browse all 8035

Trending Articles