我正在尝试为PIC 32设置一个CMake项目。这是我第一次创建CMake项目。只有一个空的main
函数的源文件。没有额外的图书馆。链接器脚本取自MPLABX项目。
我的CMakeLists.txt文件类似于这个PIC32-Project-Template。下面是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.27.4 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Tell CMake that we are cross compiling
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR mips)
set(CMAKE_CROSSCOMPILING 1)
# Generate commands in compile_commands.json without acutally building the sources
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Enable verbose output for 'make' command
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_RULE_MESSAGES OFF)
# Set device family pack (specific to microchip)
set(DFP C:/Program\ Files/Microchip/MPLABX/v6.00/packs/Microchip/PIC32MZ-EF_DFP/1.3.58)
# Set device
set(DEVICE 32MZ2048EFM100)
# Set compiler
set(COMPILER_PATH C:/Program\ Files/Microchip/xc32/v4.00/bin)
set(CMAKE_C_COMPILER ${COMPILER_PATH}/xc32-gcc.exe CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER ${COMPILER_PATH}/xc32-g++.exe CACHE PATH "" FORCE)
set(SOURCES main.cpp)
project(BuildSetup LANGUAGES CXX)
add_executable(${PROJECT_NAME}.elf ${SOURCES})
add_custom_command(
OUTPUT ${PROJECT_NAME}.hex
DEPENDS ${PROJECT_NAME}.elf
COMMAND C:/Program\ Files/Microchip/xc32/v4.00/bin/xc32-bin2hex.exe ${PROJECT_NAME}.elf
)
add_custom_target(${PROJECT_NAME}_hex ALL
DEPENDS ${PROJECT_NAME}.hex)
# Set compiler options and flags
target_compile_options(${PROJECT_NAME}.elf PUBLIC -g -x c++ -c -mprocessor=32MZ2048EFM100 -O0 -frtti -fexceptions -fno-check-new -fenforce-eh-specs -DPIC32MZ -DPIC32MZ_CURIOSITY -DPIC32MZ2048EFM100 -DXC32 -DHARMONY_V3 -mdfp=${DFP})
target_compile_definitions(${PROJECT_NAME}.elf PUBLIC XPRJ_curiosity_debug=curiosity_debug)
# Set linker options and flags
target_link_options(${PROJECT_NAME}.elf PUBLIC -mprocessor=${DEVICE} -O0)
target_link_libraries(${PROJECT_NAME}.elf "-Wl,--defsym=__MPLAB_BUILD=1,--script=\"p32MZ2048EFM100.ld\",--defsym=_min_heap_size=65536,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map=\"${PROJECT_NAME}.map\",--report-mem,--cref,--memorysummary,memoryfile.xml")
下面的CMake命令成功地在build
目录中生成了所需的makefiles。
cmake.exe -G "MinGW Makefiles" -D"CMAKE_MAKE_PROGRAM:PATH=C:\Program Files\Microchip\MPLABX\v6.00\gnuBins\GnuWin32\bin\make.exe" -B ./build
从build
目录使用make --no-print-directory
命令构建失败,并出现以下错误。如何成功构建项目?
D:\BuildSetup\cmake\bin\cmake.exe -SD:\BuildSetup -BD:\BuildSetup\build --check-build-system CMakeFiles\Makefile.cmake 0
D:\BuildSetup\cmake\bin\cmake.exe -E cmake_progress_start D:\BuildSetup\build\CMakeFiles D:\BuildSetup\build\\CMakeFiles\progress.marks
C:/Program Files/Microchip/MPLABX/v6.00/gnuBins/GnuWin32/bin/make -f CMakeFiles\Makefile2 all
C:/Program Files/Microchip/MPLABX/v6.00/gnuBins/GnuWin32/bin/make -f CMakeFiles\BuildSetup.elf.dir\build.make CMakeFiles/BuildSetup.elf.dir/depend
D:\BuildSetup\cmake\bin\cmake.exe -E cmake_depends "MinGW Makefiles" D:\BuildSetup D:\BuildSetup D:\BuildSetup\build D:\BuildSetup\build D:\BuildSetup\build\CMakeFiles\BuildSetup.elf.dir\DependInfo.cmake "--color="
C:/Program Files/Microchip/MPLABX/v6.00/gnuBins/GnuWin32/bin/make -f CMakeFiles\BuildSetup.elf.dir\build.make CMakeFiles/BuildSetup.elf.dir/build
C:\PROGRA~1\Microchip\xc32\v4.00\bin\xc32-g++.exe -DXPRJ_curiosity_debug=curiosity_debug -std=gnu++11 -g -x c++ -c -mprocessor=32MZ2048EFM100 -O0 -frtti -fexceptions -fno-check-new -fenforce-eh-specs -DPIC32MZ -DPIC32MZ_CURIOSITY -DPIC32MZ2048EFM100 -DXC32 -DHARMONY_V3 -mdfp={DFP} -MD -MT CMakeFiles/BuildSetup.elf.dir/main.cpp.obj -MF CMakeFiles\BuildSetup.elf.dir\main.cpp.obj.d -o CMakeFiles\BuildSetup.elf.dir\main.cpp.obj -c D:\BuildSetup\main.cpp
pic32m-g++.exe: error: Could not open resource file for: '32MZ2048EFM100' at '/xc32_device.info'
CMakeFiles\BuildSetup.elf.dir\build.make:74: recipe for target 'CMakeFiles/BuildSetup.elf.dir/main.cpp.obj' failed
make[2]: *** [CMakeFiles/BuildSetup.elf.dir/main.cpp.obj] Error 255
CMakeFiles\Makefile2:86: recipe for target 'CMakeFiles/BuildSetup.elf.dir/all' failed
make[1]: *** [CMakeFiles/BuildSetup.elf.dir/all] Error 2
Makefile:92: recipe for target 'all' failed
make: *** [all] Error 2
xc32_device.info
的故障位置为C:\Program Files\Microchip\MPLABX\v6.00\packs\Microchip\PIC32MZ-EF_DFP\1.3.58\xc32\
。此文件和32MZ2048EFM100
文件夹的内容与标准安装相同,无需修改。最初,我认为错误可能与xc32
或其子文件夹的访问限制有关。我为当前用户提供了所有读-写-修改访问权限,并尝试使用管理员权限执行make
命令,但无效。
1条答案
按热度按时间new9mtju1#
我的错。我在访问CMakeLists.txt文件中的变量之前错过了
$
符号。