我用 scons 编译生成的可以正常运行,但是 scons —target=cmake 后,用 cmake 编译生成的不能正常运行
cmakelists 文件如下
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m7)
#SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(CMAKE_C_COMPILER "C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-gcc.exe")
SET(CMAKE_ASM_COMPILER "C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-gcc.exe")
SET(CMAKE_C_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc --sysroot=C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/../arm-none-eabi -O0 -gdwarf-2 -g -std=gnu99")
SET(CMAKE_ASM_FLAGS " -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2")
SET(CMAKE_C_COMPILER_WORKS TRUE)
SET(CMAKE_CXX_COMPILER "C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-g++.exe")
SET(CMAKE_CXX_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc --sysroot=C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/../arm-none-eabi -O0 -gdwarf-2 -g -std=gnu++11")
SET(CMAKE_CXX_COMPILER_WORKS TRUE)
SET(CMAKE_OBJCOPY "C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-objcopy.exe")
SET(CMAKE_SIZE "C:/Users/liuya/MyApp/RT-ThreadStudio/platform/env_released/env/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-size.exe")
SET(CMAKE_EXE_LINKER_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=ZKY_CPC.map,-cref,-u,Reset_Handler -T ${CMAKE_SOURCE_DIR}/link_scripts/link.lds")
SET(CMAKE_CXX_STANDARD 14)
PROJECT(rtthread C CXX ASM)
INCLUDE_DIRECTORIES(
board
board/cubemx/Core/Inc
../../../RTT/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/CMSIS/include
../../../RTT/github/rt-thread/components/libc/compilers/common/include
../../../RTT/github/rt-thread/components/libc/compilers/newlib
"C:/Users/liuya/work/LYFCU/src/model/controller",
../../../RTT/github/rt-thread/libcpu/arm/common
../../../RTT/github/rt-thread/libcpu/arm/cortex-m7
../../../RTT/github/rt-thread/components/drivers/include
../../../RTT/github/rt-thread/components/drivers/spi
../../../RTT/github/rt-thread/components/drivers/spi/sfud/inc
"C:/Users/liuya/work/LYFCU/src",
../../../RTT/github/rt-thread/components/dfs/include
../../../RTT/github/rt-thread/components/dfs/filesystems/elmfat
../../../RTT/github/rt-thread/components/dfs/filesystems/ramfs
../../../RTT/github/rt-thread/components/dfs/filesystems/romfs
../../../RTT/github/rt-thread/components/finsh
"C:/Users/liuya/work/LYFCU/src/model/fms",
hal_drivers
hal_drivers/config
"C:/Users/liuya/work/LYFCU/src/model/ins",
.
../../../RTT/github/rt-thread/include
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Inc
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Include
../../../RTT/github/rt-thread/components/libc/posix/delay
../../../RTT/github/rt-thread/components/libc/posix/io/poll
../../../RTT/github/rt-thread/components/libc/posix/io/stdio
../../../RTT/github/rt-thread/components/libc/posix/ipc
)
ADD_DEFINITIONS(
-DHAVE_CCONFIG_H
-DRT_USING_LIBC
-DRT_USING_NEWLIB
-DSTM32H743xx
-DUSE_HAL_DRIVER
-D_POSIX_C_SOURCE=1
-D__RTTHREAD__
)
SET(PROJECT_SOURCES
../../src/lib/airspeed/airspeed.c
board/board_test.c
board/cubemx/Core/Src/stm32h7xx_hal_msp.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h743xx.s
board/board_device.c
board/board.c
board/can_service.c
../../../RTT/github/rt-thread/components/libc/compilers/common/cctype.c
../../../RTT/github/rt-thread/components/libc/compilers/common/cstdio.c
../../../RTT/github/rt-thread/components/libc/compilers/common/cstdlib.c
../../../RTT/github/rt-thread/components/libc/compilers/common/cstring.c
../../../RTT/github/rt-thread/components/libc/compilers/common/ctime.c
../../../RTT/github/rt-thread/components/libc/compilers/common/cwchar.c
../../../RTT/github/rt-thread/components/libc/compilers/newlib/syscalls.c
../../src/model/controller/params_define.c
../../src/model/controller/controller_mc.c
../../src/model/controller/controller_fw.c
../../../RTT/github/rt-thread/libcpu/arm/common/backtrace.c
../../../RTT/github/rt-thread/libcpu/arm/common/div0.c
../../../RTT/github/rt-thread/libcpu/arm/common/showmem.c
../../../RTT/github/rt-thread/libcpu/arm/cortex-m7/context_gcc.S
../../../RTT/github/rt-thread/libcpu/arm/cortex-m7/cpu_cache.c
../../../RTT/github/rt-thread/libcpu/arm/cortex-m7/cpuport.c
../../../RTT/github/rt-thread/components/drivers/can/can.c
../../../RTT/github/rt-thread/components/drivers/hwtimer/hwtimer.c
../../../RTT/github/rt-thread/components/drivers/i2c/i2c-bit-ops.c
../../../RTT/github/rt-thread/components/drivers/i2c/i2c_core.c
../../../RTT/github/rt-thread/components/drivers/i2c/i2c_dev.c
../../../RTT/github/rt-thread/components/drivers/ipc/completion.c
../../../RTT/github/rt-thread/components/drivers/ipc/dataqueue.c
../../../RTT/github/rt-thread/components/drivers/ipc/pipe.c
../../../RTT/github/rt-thread/components/drivers/ipc/ringblk_buf.c
../../../RTT/github/rt-thread/components/drivers/ipc/ringbuffer.c
../../../RTT/github/rt-thread/components/drivers/ipc/waitqueue.c
../../../RTT/github/rt-thread/components/drivers/ipc/workqueue.c
../../../RTT/github/rt-thread/components/drivers/misc/adc.c
../../../RTT/github/rt-thread/components/drivers/misc/pin.c
../../../RTT/github/rt-thread/components/drivers/mtd/mtd_nor.c
../../../RTT/github/rt-thread/components/drivers/rtc/rtc.c
../../../RTT/github/rt-thread/components/drivers/serial/serial_v2.c
../../../RTT/github/rt-thread/components/drivers/spi/qspi_core.c
../../../RTT/github/rt-thread/components/drivers/spi/sfud/src/sfud.c
../../../RTT/github/rt-thread/components/drivers/spi/sfud/src/sfud_sfdp.c
../../../RTT/github/rt-thread/components/drivers/spi/spi_core.c
../../../RTT/github/rt-thread/components/drivers/spi/spi_dev.c
../../../RTT/github/rt-thread/components/drivers/spi/spi_flash_sfud.c
../../src/drivers/airspeed/ms4525/drv_ms4525.c
../../src/drivers/mag/vcm5883/drv_vcm5883.c
../../src/startup.c
../../../RTT/github/rt-thread/components/dfs/filesystems/elmfat/dfs_elm.c
../../../RTT/github/rt-thread/components/dfs/filesystems/elmfat/ff.c
../../../RTT/github/rt-thread/components/dfs/filesystems/elmfat/ffunicode.c
../../../RTT/github/rt-thread/components/dfs/filesystems/ramfs/dfs_ramfs.c
../../../RTT/github/rt-thread/components/dfs/filesystems/romfs/dfs_romfs.c
../../../RTT/github/rt-thread/components/dfs/filesystems/romfs/romfs.c
../../../RTT/github/rt-thread/components/dfs/src/dfs.c
../../../RTT/github/rt-thread/components/dfs/src/dfs_file.c
../../../RTT/github/rt-thread/components/dfs/src/dfs_fs.c
../../../RTT/github/rt-thread/components/dfs/src/dfs_posix.c
../../../RTT/github/rt-thread/components/finsh/shell.c
../../../RTT/github/rt-thread/components/finsh/msh.c
../../../RTT/github/rt-thread/components/finsh/msh_parse.c
../../../RTT/github/rt-thread/components/finsh/cmd.c
../../../RTT/github/rt-thread/components/finsh/msh_file.c
../../src/hal/airspeed/airspeed.c
../../src/hal/serialX/serialX.c
../../src/hal/mag/mag.c
../../src/hal/hrt/hrt.c
../../src/hal/gps/gps.c
../../src/hal/gyro/gyro.c
../../src/hal/actuator/actuator.c
../../src/hal/serialX/serial_rs485.c
hal_drivers/drv_gpio.c
hal_drivers/drv_mpu.c
hal_drivers/drv_uartX.c
hal_drivers/drv_qspi.c
hal_drivers/drv_spi.c
hal_drivers/drv_adc.c
hal_drivers/drv_soft_i2c.c
hal_drivers/drv_fdcan.c
hal_drivers/drv_hrt.c
hal_drivers/drv_qspi_flash.c
hal_drivers/drv_rtc.c
hal_drivers/drv_common.c
hal_drivers/drv_hwtimer.c
../../../RTT/github/rt-thread/src/clock.c
../../../RTT/github/rt-thread/src/components.c
../../../RTT/github/rt-thread/src/device.c
../../../RTT/github/rt-thread/src/idle.c
../../../RTT/github/rt-thread/src/ipc.c
../../../RTT/github/rt-thread/src/irq.c
../../../RTT/github/rt-thread/src/kservice.c
../../../RTT/github/rt-thread/src/mem.c
../../../RTT/github/rt-thread/src/memheap.c
../../../RTT/github/rt-thread/src/mempool.c
../../../RTT/github/rt-thread/src/object.c
../../../RTT/github/rt-thread/src/scheduler.c
../../../RTT/github/rt-thread/src/thread.c
../../../RTT/github/rt-thread/src/timer.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_lptim.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_nor.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
../../../RTT/github/rt-thread/bsp/stm32/libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c
../../src/module/sensor/sensor_baro.c
../../src/module/file_manager/file_ex_ops.c
../../src/module/workqueue/work_queue.c
../../src/module/ipc/uMCN.c
../../src/module/math/light_matrix.c
../../src/module/file_manager/yxml.c
../../src/module/workqueue/workqueue_manager.c
../../src/module/system/cpusage.c
../../src/module/system/systime.c
../../src/module/math/axis_angle.c
../../src/module/sensor/sensor_mag.c
../../src/module/file_manager/file_manager.c
../../src/module/sensor/sensor_airspeed.c
../../src/module/sensor/sensor_gps.c
../../src/module/math/quaternion.c
../../src/module/math/matrix.c
../../src/module/param/param.c
../../src/module/file_manager/rt_vsprintf.c
../../src/module/math/euler.c
../../src/module/sensor/sensor_imu.c
../../src/module/sensor/sensor_hub.c
../../src/module/system/sys_param.c
../../../RTT/github/rt-thread/components/libc/posix/delay/delay.c
../../src/protocol/vklink/vklink.c
)
LINK_DIRECTORIES(
)
LINK_LIBRARIES(
c
m
)
ADD_EXECUTABLE({CMAKE_PROJECT_NAME}.elf {PROJECT_SOURCES})
ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD
COMMAND {CMAKE_OBJCOPY} -O binary {CMAKE_PROJECT_NAME}.elf {CMAKE_PROJECT_NAME}.bin COMMAND {CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)
rtconfig.py 文件如下
import os
import sys
import rtconfig
FMU path
FMU_ROOT = os.path.normpath(os.getcwd() + '/../..')
RTOS path
RTT_ROOT = 'C:/Users/liuya/work/RTT/github/rt-thread'
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'build/ZKY_CPC.' + rtconfig.TARGET_EXT
env = Environment(tools=['mingw'],
AS=rtconfig.AS, ASFLAGS=rtconfig.AFLAGS,
CC=rtconfig.CC, CFLAGS=rtconfig.CFLAGS,
AR=rtconfig.AR, ARFLAGS='-rc',
CXX=rtconfig.CXX, CXXFLAGS=rtconfig.CXXFLAGS,
LINK=rtconfig.LINK, LINKFLAGS=rtconfig.LFLAGS)
Add sys execute PATH to env PATH
env.PrependENVPath('PATH', os.getenv('PATH'))
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
if rtconfig.PLATFORM == 'iar':
env.Replace(
CCCOM=['CC CCFLAGS CPPFLAGS _CPPDEFFLAGS _CPPINCFLAGS -o TARGET $SOURCES'])
env.Replace(ARFLAGS=[''])
env.Replace(
LINKCOM=['LINK SOURCES LINKFLAGS -o TARGET --map project.map'])
Export('RTT_ROOT')
Export('FMU_ROOT')
Export('rtconfig')
prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
cwd = str(Dir('#'))
list = os.listdir(FMU_ROOT)
vdir = 'build/fmu'
for d in list:
path = os.path.join(FMU_ROOT, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs.extend(SConscript(os.path.join(path, 'SConscript'),
variant_dir=vdir + '/' + d, duplicate=0))
print env.get('CPPPATH', [''])
env.Tool('compilation_db')
env.CompilationDatabase()
make a building
DoBuilding(TARGET, objs)
对比生成的二进制文件,确实有一点字节差异,请教一下是哪出了问题