我试图在QEMU中使用半托管方式为我的项目建立一个测试环境。到目前为止,我对hello.c在这个答案之后没有任何问题,但是我很难让它与CMake一起工作。
下面是我如何构建完全相同的hello.c (pastebin上的工具链文件):
C:\hello_cmake>cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake . -Btmp
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Configuring done
-- Generating done
-- Build files have been written to: C:/hello_cmake/tmp
C:\hello_cmake>cmake --build tmp --verbose
"C:/Program Files/CMake/bin/cmake.exe" -SC:/hello_cmake -BC:/hello_cmake/tmp --check-build-system CMakeFiles/Makefile.cmake 0
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_progress_start C:/hello_cmake/tmp/CMakeFiles C:/hello_cmake/tmp//CMakeFiles/progress.marks
C:/buildtools/bin/make.exe -f CMakeFiles/Makefile2 all
make.exe[1]: Entering directory 'C:/hello_cmake/tmp'
C:/buildtools/bin/make.exe -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/depend
make.exe[2]: Entering directory 'C:/hello_cmake/tmp'
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_depends "Unix Makefiles" C:/hello_cmake C:/hello_cmake C:/hello_cmake/tmp C:/hello_cmake/tmp C:/hello_cmake/tmp/CMakeFiles/hello.dir/DependInfo.cmake --color=
make.exe[2]: Leaving directory 'C:/hello_cmake/tmp'
C:/buildtools/bin/make.exe -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/build
make.exe[2]: Entering directory 'C:/hello_cmake/tmp'
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
"C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe" -specs=rdimon.specs -mcpu=cortex-a9 -O0 -g -MD -MT CMakeFiles/hello.dir/hello.c.obj -MF CMakeFiles/hello.dir/hello.c.obj.d -o CMakeFiles/hello.dir/hello.c.obj -c C:/hello_cmake/hello.c
[100%] Linking C executable hello
"C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe" -lc -lrdimon -lc -lrdimon "CMakeFiles/hello.dir/hello.c.obj" -o hello
make.exe[2]: Leaving directory 'C:/hello_cmake/tmp'
[100%] Built target hello
make.exe[1]: Leaving directory 'C:/hello_cmake/tmp'
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_progress_start C:/hello_cmake/tmp/CMakeFiles 0下面是我如何调用QEMU:
qemu-system-arm.exe -nographic -machine xilinx-zynq-a9 -cpu cortex-a9 -monitor none -serial stdio -kernel app -m 512 -semihostingQEMU几乎立即退出,而不产生任何输出,但是-d exec和-d init日志看起来像是正在运行的代码,并且半托管实际上是有效的:
...
Trace 0: 0000000004705540 [00000400/0000828c/000005a0/ff000000] __libc_init_array
Trace 0: 0000000004705780 [00000400/000081ec/000005a0/ff000000] frame_dummy
Trace 0: 00000000047058c0 [00000400/00010460/000005a0/ff000000] main
Trace 0: 0000000004705c00 [00000400/00029158/000005a0/ff000000] printf
Trace 0: 0000000004706040 [00000400/000301f0/000005a0/ff000000] _vfprintf_r
Trace 0: 0000000004706440 [00000400/000375b8/000005a0/ff000000] _localeconv_r
Trace 0: 00000000047065c0 [00000400/0003020c/000005a0/ff000000] _vfprintf_r
Trace 0: 00000000047067c0 [00000400/0000a704/000005a0/ff000000] strlen
...
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0xc
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0x13
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0x5
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...问题是: CMake做什么(或不做)破坏printf输出?
请记录在案:
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10)QEMU emulator version 7.0.0 (v7.0.0-11902-g1d935f4a02-dirty)Microsoft Windows [Version 10.0.19044.1645]cmake version 3.22.2发布于 2022-05-12 01:15:52
我无法找到您正在使用的CMakeLists.lst,但我能够使用以下文件生成/运行hello.elf:
hello.c
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv)
{
printf("Hello, World!\n");
return EXIT_SUCCESS;
}CMakeLists.lst
project(hello_world)
add_executable(hello.elf hello.c)toolchain.cmake (因为这是一个链接选项,因此不需要对链接器- -lc使用--specs=rdimon.specs选项,因为使用rdimon.specs是多余的):
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR Cortex-A9)
# Common options
add_compile_options(
-mcpu=cortex-a9
-O0
-g
)
set(CMAKE_EXE_LINKER_FLAGS "--specs=rdimon.specs")
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
find_program(CMAKE_C_COMPILER $ENV{ARMGCC_DIR}/bin/arm-none-eabi-gcc.exe)
find_program(CMAKE_CXX_COMPILER $ENV{ARMGCC_DIR}/bin/arm-none-eabi-g++.exe)
find_program(CMAKE_ASM_COMPILER $ENV{ARMGCC_DIR}/bin/arm-none-eabi-gcc.exe)
find_program(CMAKE_OBJCOPY $ENV{ARMGCC_DIR}/bin/arm-none-eabi-objcopy)
find_program(CMAKE_OBJDUMP $ENV{ARMGCC_DIR}/bin/arm-none-eabi-objdump)
find_program(CMAKE_NM $ENV{ARMGCC_DIR}/bin/arm-none-eabi-nm)
find_program(CMAKE_LINKER $ENV{ARMGCC_DIR}/bin/arm-none-eabi-ld)build-cmake.cmd
@set ARMGCC_DIR=D:\opt\arm\10\gcc-arm-10.3-2021.07-mingw-w64-i686-arm-none-eabi
@set CMAKE=D:\opt\cmake-3.23.1-windows-x86_64\bin\cmake
@set MAKE=D:\opt\stackoverflow\72199730\make.exe
@set QEMU_SYSTEM_ARM=D:\opt\qemu-7.0.0\qemu-system-arm
%CMAKE% -E rm -rf tmp
%CMAKE% -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake . -Btmp
%MAKE% -C tmp
%QEMU_SYSTEM_ARM% -semihosting --semihosting-config enable=on,target=native -nographic -serial mon:stdio -machine xilinx-zynq-a9 -m 768M -cpu cortex-a9 -kernel tmp\hello.elf处决:
D:\opt\stackoverflow\72199730>build-cmake.cmd
D:\opt\stackoverflow\72199730>D:\opt\cmake-3.23.1-windows-x86_64\bin\cmake -E rm -rf tmp
D:\opt\stackoverflow\72199730>D:\opt\cmake-3.23.1-windows-x86_64\bin\cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake . -Btmp
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Configuring done
-- Generating done
-- Build files have been written to: D:/opt/stackoverflow/72199730/tmp
D:\opt\stackoverflow\72199730>D:\opt\stackoverflow\72199730\make.exe -C tmp
make: Entering directory 'D:/opt/stackoverflow/72199730/tmp'
make[1]: Entering directory 'D:/opt/stackoverflow/72199730/tmp'
make[2]: Entering directory 'D:/opt/stackoverflow/72199730/tmp'
make[2]: Leaving directory 'D:/opt/stackoverflow/72199730/tmp'
make[2]: Entering directory 'D:/opt/stackoverflow/72199730/tmp'
[ 50%] Building C object CMakeFiles/hello.elf.dir/hello.c.obj
[100%] Linking C executable hello.elf
make[2]: Leaving directory 'D:/opt/stackoverflow/72199730/tmp'
[100%] Built target hello.elf
make[1]: Leaving directory 'D:/opt/stackoverflow/72199730/tmp'
make: Leaving directory 'D:/opt/stackoverflow/72199730/tmp'
D:\opt\stackoverflow\72199730>D:\opt\qemu-7.0.0\qemu-system-arm -semihosting --semihosting-config enable=on,target=native -nographic -serial mon:stdio -machine xilinx-zynq-a9 -m 768M -cpu cortex-a9 -kernel tmp\hello.elf
Hello, World!使用的版本:
\opt\arm\10\gcc-arm-10.3-2021.07-mingw-w64-i686-arm-none-eabi\bin\arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)) 10.3.1 20210621
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\opt\cmake-3.23.1-windows-x86_64\bin\cmake.exe --version
cmake version 3.23.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
D:\opt\stackoverflow\72199730>\opt\qemu-7.0.0\qemu-system-arm.exe --version
QEMU emulator version 7.0.0 (v7.0.0-11902-g1d935f4a02-dirty)
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
make --version
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
wmic os get version
Version
10.0.19044https://stackoverflow.com/questions/72199730
复制相似问题