Linux下使用MRS工具鏈編譯CH32鏈接報(bào)錯(cuò)

我在ubuntu22.04環(huán)境下解壓最新版的MRS_Toolchain,并在我的工程中使用CMake編譯項(xiàng)目

這是我的代碼鏈接:https://gitee.com/netube/v208_ble

目前可以順利通過(guò)編譯階段,但到了鏈接的時(shí)候出現(xiàn)了一些錯(cuò)誤,內(nèi)容如下:

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/lib/rv32imac/ilp32/libg.a(lib_a-exit.o): in function `.L0 ':

exit.c:(.text.exit+0x20): undefined reference to `_exit'

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/lib/rv32imac/ilp32/crt0.o: in function `.L0 ':

(.text+0x2e): undefined reference to `main'

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: CMakeFiles/ch32v208.dir/device/Debug/debug.c.o: in function `_write':

/home/netube/mywork/v208_ble/device/Debug/debug.c:171: undefined reference to `_heap_end'

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: /home/netube/mywork/v208_ble/device/Debug/debug.c:171: undefined reference to `_heap_end'

collect2: error: ld returned 1 exit status

make[2]: *** [CMakeFiles/ch32v208.dir/build.make:465: ch32v208] Error 1

make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/ch32v208.dir/all] Error 2

make: *** [Makefile:91: all] Error 2


最后附上CMakeLists.txt的內(nèi)容

cmake_minimum_required(VERSION 3.12)

set(PROJECT_NAME "ch32v208")

project(${PROJECT_NAME})

# 添加源文件

file(GLOB USER_SOURCES user/*.c)

file(GLOB MSP_SOURCES msp/*.c)

file(GLOB BSP_SOURCES bsp/*.c)

file(GLOB APP_SOURCES app/*.c)

file(GLOB DEV_CORE_SOURCES device/Core/*.c)

file(GLOB DEV_DEBUG_SOURCES device/Debug/*.c)

file(GLOB DEV_PER_SOURCES device/Peripheral/src/*.c)

# 設(shè)置可執(zhí)行目標(biāo)與源碼

add_executable(${PROJECT_NAME}

? ? device/Startup/startup_ch32v20x_D8W.S

? ? ${USER_SOURCES}

? ? ${MSP_SOURCES}

? ? ${BSP_SOURCES}

? ? ${APP_SOURCES}

? ? ${DEV_CORE_SOURCES}

? ? ${DEV_DEBUG_SOURCES}

? ? ${DEV_PER_SOURCES}

)

# 添加頭文件目錄

include_directories(

? ? PRIVATE

? ? user

? ? msp

? ? bsp

? ? app

? ? device/Core

? ? device/Debug

? ? device/Peripheral/inc

? ? lib

? ? ${OpenCV_INCLUDE_DIRS}

)

# 設(shè)置編譯宏

add_compile_definitions(CH32V20x_D8W)

# 設(shè)置交叉工具鏈

set(CMAKE_C_COMPILER /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/riscv-none-embed-gcc)

set(CMAKE_CXX_COMPILER /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/riscv-none-embed-g++)

# 設(shè)置DEBUG與優(yōu)化等級(jí)

set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")

# 設(shè)置語(yǔ)言標(biāo)準(zhǔn)

set(CMAKE_C_STANDARD 99)

set(CMAKE_CXX_STANDARD 11)

# 編譯參數(shù)

# 設(shè)定指令集 設(shè)定ABI 小數(shù)據(jù)段限制 函數(shù)調(diào)用期間保存和恢復(fù)寄存器的狀態(tài)

add_compile_options(-march=rv32imac -mabi=ilp32 -msmall-data-limit=8 -msave-restore)

# 不限制錯(cuò)誤/警告消息的長(zhǎng)度 char為有符號(hào)類型 函數(shù)放在單獨(dú)節(jié) 數(shù)據(jù)放在單獨(dú)節(jié) 禁止合并同名全局變量

add_compile_options(-fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common)

# 鏈接參數(shù)

# 設(shè)置sdk提供的ld文件

add_link_options(-T device/Ld/Link.ld)

# 設(shè)定指令集 設(shè)定ABI 刪除未使用的節(jié) 打印內(nèi)存使用情況 生成MAP文件 使用限制C庫(kù)和系統(tǒng)調(diào)用的規(guī)范文件

add_link_options(-march=rv32imac -mabi=ilp32 -nostartfiles -Xlinker --gc-sections -Wl,--print-memory-usage -Wl,-Map,${PROJECT_NAME}.map --specs=nano.specs --specs=nosys.specs)

# 編譯后自動(dòng)輸出 ELF HEX BIN

# 添加自定義命令以生成ELF、HEX和BIN文件

add_custom_command(

? ? TARGET ${PROJECT_NAME} POST_BUILD

? ? COMMAND ${CMAKE_OBJCOPY} -O elf32-littleriscv $${PROJECT_NAME}> ${CMAKE_BINARY_DIR}/output/${PROJECT_NAME}.elf

? ? COMMAND ${CMAKE_OBJCOPY} -O ihex $${PROJECT_NAME}> ${CMAKE_BINARY_DIR}/output/${PROJECT_NAME}.hex

? ? COMMAND ${CMAKE_OBJCOPY} -O binary $${PROJECT_NAME}> ${CMAKE_BINARY_DIR}/output/${PROJECT_NAME}.bin

)


工具鏈的內(nèi)容未作任何改動(dòng),解壓在路徑/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/

我在CMakeLists.txt中指定了編譯器的路徑:

set(CMAKE_C_COMPILER /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/riscv-none-embed-gcc)
set(CMAKE_CXX_COMPILER /home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/riscv-none-embed-g++)

cmake生成makefile文件和使用make命令編譯是沒(méi)有問(wèn)題的,但是在鏈接的過(guò)程中,出現(xiàn)了報(bào)錯(cuò),似乎沒(méi)有使用:

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/bin/riscv-none-embed-ld

而是用了這個(gè)位置的鏈接器:

/home/netube/mywork/MRS_Toolchain_Linux_x64_V1.80/RISC-V_Embedded_GCC/riscv-none-embed/bin/ld

我想知道鏈接出錯(cuò)的原因是否和這個(gè)鏈接器有關(guān)系,或者是我的CMakeLists.txt沒(méi)有寫對(duì)嗎,我用習(xí)慣了MDK開(kāi)發(fā)單片機(jī),第一次用工具鏈編譯項(xiàng)目,沒(méi)想到困難重重,希望有l(wèi)inux下使用工具鏈編譯的朋友可以為我指點(diǎn)迷津,萬(wàn)分感謝




icon_rar.gifv208_ble-main.zip

您好:附件是我?guī)湍薷暮蟮腸make工程,目前ubuntu 20.04上測(cè)試可以成功編譯。305f05953ba27ed42a2e998426b62bd.png請(qǐng)根據(jù)壓縮包中的readme.txt文件相關(guān)說(shuō)明執(zhí)行編譯


收到,已經(jīng)成功編譯,謝謝


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频