You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu编译Raspberry Pi Pico示例遇CMake命令‘pico_add_extra_outputs’未知错误

Raspberry Pi Pico示例编译错误:Unknown CMake command "pico_add_extra_outputs"

问题详情

在Ubuntu系统中编译Raspberry Pi Pico官方示例时,触发如下CMake错误:

CMake Error at serial/CMakeLists.txt:9 (pico_add_extra_outputs):
Unknown CMake command "pico_add_extra_outputs".

注释掉pico_add_extra_outputs(hello_serial)和example_auto_set_url(hello_serial)两行后,编译可通过,但无法生成uf2、hex等目标输出文件。涉事CMake代码片段如下:

add_executable(hello_serial
        hello_serial.c
        )

# pull in common dependencies
target_link_libraries(hello_serial pico_stdlib)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(hello_serial)

# add url via pico_set_program_url
example_auto_set_url(hello_serial)

解决步骤

1. 确保Pico SDK路径正确配置

pico_add_extra_outputs和example_auto_set_url是Pico SDK及官方示例库提供的专属CMake函数,找不到命令的核心原因是CMake未正确加载相关配置。

  • 编译前先设置Pico SDK的环境变量:
    export PICO_SDK_PATH="/实际的pico-sdk路径"
    
  • 确保项目根目录的CMakeLists.txt开头已导入SDK配置:
    include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
    

2. 规范CMakeLists.txt初始化流程

项目根CMakeLists.txt必须按照官方要求的顺序初始化SDK,示例结构如下:

cmake_minimum_required(VERSION 3.13)

# 必须在project()之前导入SDK配置
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

project(hello_serial_demo)

# 初始化Pico SDK
pico_sdk_init()

# 后续的目标定义与配置
add_executable(hello_serial hello_serial.c)
target_link_libraries(hello_serial pico_stdlib)
pico_add_extra_outputs(hello_serial)
example_auto_set_url(hello_serial)

3. 清理缓存后重新构建

旧的构建缓存可能导致配置异常,执行以下命令重置构建环境:

rm -rf build
mkdir build && cd build
cmake ..
make

完成以上操作后,pico_add_extra_outputs会正常生成所需的uf2、hex等目标文件,example_auto_set_url也能正常工作。

内容的提问来源于stack exchange,提问作者Mohan B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:42:20