Closed HackXIt closed 2 months ago
By coincidence we were talking about this today...
Yes, it's a common problem I'm afraid. Some people work around the issue https://forums.raspberrypi.com/viewtopic.php?t=350982
On windows - which doesn't have a native compiler - the following is included before including pico_sdk_import.cmake
set(Pioasm_TARGET Pioasm)
set(Pioasm_EXECUTABLE ${pico-sdk-tools_DIR}/pioasm.exe)
if(NOT TARGET ${Pioasm_TARGET})
add_executable(${Pioasm_TARGET} IMPORTED)
endif()
set_property(TARGET ${Pioasm_TARGET} PROPERTY IMPORTED_LOCATION ${Pioasm_EXECUTABLE})
set(Pioasm_FOUND 1)
set(ELF2UF2_TARGET ELF2UF2)
set(ELF2UF2_EXECUTABLE ${pico-sdk-tools_DIR}/elf2uf2.exe)
if(NOT TARGET ${ELF2UF2_TARGET})
add_executable(${ELF2UF2_TARGET} IMPORTED)
endif()
set_property(TARGET ${ELF2UF2_TARGET} PROPERTY IMPORTED_LOCATION ${ELF2UF2_EXECUTABLE})
set(ELF2UF2_FOUND 1)
That's great news!
I have included your cmake snippet before the import, but it didn't seem to do the trick just yet.
I quickly applied my hack to get around the simple test program error, which I can't seem to fix:
(For some reason I always get Detecting C compiler ABI info - failed
and Detecting CXX compiler ABI info - failed
, which I believe results in the simple test program error whenever using conan to build)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
But now I get the following build error:
I fixed the additional build errors by enforcing the target -mcpu
and -march
in the conan profile.
This did not occur to me beforehand, because these flags are normally set when using pico_sdk_import.cmake
and pico_sdk_init()
.
I will continue this in the conan issue, since the package manager introduces this weird behaviour.
Thanks for all the insight, there were definitly one or two steps necessary to get the core issue, would have taken me way longer without your snippet to avoid pioasm
and elf2uf2
.
Greetings,
I have an open issue on conan which describes the following build error when using the pico SDK in a conan project:
Build error
``` ======== Calling build() ======== conanfile.py (pico-conan-blink/0.0.1): Calling build() conanfile.py (pico-conan-blink/0.0.1): Running CMake.configure() conanfile.py (pico-conan-blink/0.0.1): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/rini/git-stash/pico-conan-blink/build/Debug/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/rini/git-stash/pico-conan-blink" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "/home/rini/git-stash/pico-conan-blink" -- Using Conan toolchain: /home/rini/git-stash/pico-conan-blink/build/Debug/generators/conan_toolchain.cmake Using PICO_SDK_PATH from environment ('/home/rini/pico/sdk') PICO_SDK_PATH is /home/rini/pico/sdk Defaulting PICO_PLATFORM to rp2040 since not specified. -- Conan toolchain: C++ Standard 17 with extensions ON -- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF -- The C compiler identification is GNU 12.2.1 -- The CXX compiler identification is GNU 12.2.1 -- The ASM compiler identification is GNU -- Found assembler: /usr/bin/arm-none-eabi-gcc -- Detecting C compiler ABI info Using PICO_SDK_PATH from environment ('/home/rini/pico/sdk') PICO_SDK_PATH is /home/rini/pico/sdk Defaulting PICO_PLATFORM to rp2040 since not specified. Defaulting PICO platform compiler to pico_arm_gcc since not specified. PICO compiler is pico_arm_gcc -- Detecting C compiler ABI info - failed -- Check for working C compiler: /usr/bin/arm-none-eabi-gcc Using PICO_SDK_PATH from environment ('/home/rini/pico/sdk') PICO_SDK_PATH is /home/rini/pico/sdk Defaulting PICO_PLATFORM to rp2040 since not specified. Defaulting PICO platform compiler to pico_arm_gcc since not specified. PICO compiler is pico_arm_gcc -- Check for working C compiler: /usr/bin/arm-none-eabi-gcc - broken CMake Error at /usr/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message): The C compiler "/usr/bin/arm-none-eabi-gcc" is not able to compile a simple test program. It fails with the following output: Change Dir: /home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeScratch/TryCompile-j07YgO Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_0f430/fast && /usr/bin/gmake -f CMakeFiles/cmTC_0f430.dir/build.make CMakeFiles/cmTC_0f430.dir/build gmake[1]: Entering directory '/home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeScratch/TryCompile-j07YgO' Building C object CMakeFiles/cmTC_0f430.dir/testCCompiler.c.o /usr/bin/arm-none-eabi-gcc -O3 -DNDEBUG -o CMakeFiles/cmTC_0f430.dir/testCCompiler.c.o -c /home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeScratch/TryCompile-j07YgO/testCCompiler.c Linking C executable cmTC_0f430 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0f430.dir/link.txt --verbose=1 /usr/bin/arm-none-eabi-gcc -O3 -DNDEBUG CMakeFiles/cmTC_0f430.dir/testCCompiler.c.o -o cmTC_0f430 /usr/lib/gcc/arm-none-eabi/12.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.1/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): in function `exit': /build/newlib-afIbHz/newlib-3.3.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit' collect2: error: ld returned 1 exit status gmake[1]: *** [CMakeFiles/cmTC_0f430.dir/build.make:99: cmTC_0f430] Error 1 gmake[1]: Leaving directory '/home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeScratch/TryCompile-j07YgO' gmake: *** [Makefile:127: cmTC_0f430/fast] Error 2 CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:30 (project) -- Configuring incomplete, errors occurred! See also "/home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeOutput.log". See also "/home/rini/git-stash/pico-conan-blink/build/Debug/CMakeFiles/CMakeError.log". ERROR: conanfile.py (pico-conan-blink/0.0.1): Error in build() method, line 65 cmake.configure(cli_args=common_cmake_args) ConanException: Error 1 while executing ```Here is a somewhat minimal example on what our CMakeLists look like in our RP2040 projects:
CMakeLists.txt
```cmake cmake_minimum_required(VERSION 3.13...3.27) include(FetchContent) # PICO_SDK ------------------------------------------------------------------------------ # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) if(NOT DEFINED $ENV{PICO_SDK_PATH}) # Pull in Raspberry Pi Pico SDK (must be before project) message(STATUS "PICO_SDK_PATH not defined.") if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/deps/pico-sdk) message(STATUS "Using path: ${CMAKE_CURRENT_BINARY_DIR}/deps/pico-sdk") include(${CMAKE_CURRENT_BINARY_DIR}/deps/pico-sdk/pico_sdk_init.cmake) elseif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) message(STATUS "Using path: ${CMAKE_CURRENT_LIST_DIR}") include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) else() message(FATAL_ERROR "PICO_SDK_PATH not defined and pico_sdk_import.cmake not found.") endif() else() message(STATUS "PICO_SDK_PATH defined. Using path: $ENV{PICO_SDK_PATH}") include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) endif() set(PICO_BOARD pico CACHE STRING "Board type") if (PICO_SDK_VERSION_STRING VERSION_LESS "1.5.0") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.5.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") endif() project(pico-conan-blink LANGUAGES C CXX ASM VERSION 0.0.1) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() # create disassembly with source function(pico_add_dis_output2 TARGET) add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJDUMP} -S $And here is a somewhat minimal
conanfile.py
that goes along with that:conanfile.py
```python from conan import ConanFile from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps from conan.tools.scm import Git from conan.tools.files import get class BlinkRecipe(ConanFile): name = "pico-conan-blink" version = "0.0.1" package_type = "application" arch = "armv6" # Optional metadata license = "" author = "" description = "Conan + Pico SDK Toolchain example with blink code" # Binary configuration settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "parallel": [True, False]} default_options = {"shared": False, "parallel": True} # Sources are located in the same place as this recipe, copy them to the recipe exports_sources = "src/*", "CMakeLists.txt" def layout(self): cmake_layout(self, src_folder=".", build_folder="build") def source(self): # get(self, "https://github.com/raspberrypi/pico-sdk/archive/refs/tags/1.5.1.tar.gz", destination="deps/pico-sdk", strip_root=True) pass def requirements(self): # Any custom static library packages go here pass def build_requirements(self): pass # def layout(self): # self.folders.source = "src" # self.folders.build = "build" # self.cpp.source.includedirs = ["inc"] def generate(self): deps = CMakeDeps(self) deps.generate() tc = CMakeToolchain(self) tc.extra_cflags = ["--mcpu=cortex-m0plus", "-mthumb"] tc.extra_cxxflags = ["--mcpu=cortex-m0plus", "-mthumb"] tc.preprocessor_definitions["PICO_SDK_PATH"] = "deps/pico-sdk" tc.generate() def build(self): # It was also attempted to use the PICO_SDK_PATH from the environment here - the behaviour is the same get(self, "https://github.com/raspberrypi/pico-sdk/archive/refs/tags/1.5.1.tar.gz", destination="deps/pico-sdk", strip_root=True) common_cmake_args = [] cmake = CMake(self) cmake.configure(cli_args=common_cmake_args) if self.options.parallel: common_cmake_args += ["--parallel"] cmake.build(cli_args=common_cmake_args) ```Conan does not provide the native C/C++ compiler to the build process, but only
arm-none-eabi
cross-compiler.Despite my CMakeLists.txt not using the cmake functions provided by the
pioasm
andelf2uf2
tools, there still seems to be a hidden step that does require some sort of native compiler, resulting in the simple test program error.Am I doing something wrong or forgetting something?
I've setup conan so that it loads the
pico_sdk_import.cmake
during the build step and it's visible in the logs that configuration catches multiple C/C++ compiler setups (I am yet unsure why it is done multiple times, I suspect due to the additional import in myCMakeLists.txt
)However, from there on, the project should actually compile just fine, since it has the cross-compiler, it finds the SDK, so I don't see a reason why it should fail in the way it does.
Without conan the project compiles fine, which led me here to ask where this somewhat hidden dependency on the native C/C++ compiler lies or what does specific error means in the context of the pico SDK.