I am trying to use arm-none-eabi-gcc with CMake but am getting an error about an undefined reference to "_exit". The following is the terminal output after running cmake (the first line is the command):
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-g++.exe -Hf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox "-Bf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug" -G Ninja
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 10.3.1
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeTmp
Run Build Command(s):F:/Resources/Dev/Tools/MinGW/MinGW-9.0.0-x64/bin/ninja.exe cmTC_1a12b && [1/2] Building C object CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj
[2/2] Linking C executable cmTC_1a12b
FAILED: cmTC_1a12b
cmd.exe /C "cd . && F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj -o cmTC_1a12b && cd ."
f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:41 (project)
-- Configuring incomplete, errors occurred!
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeOutput.log".
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeError.log".
I have tried the following solution (i.e. adding simply adding -specs=nosys.specs to my CMakeLists.txt but to no avail. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_STANDARD 99)
# Project variables
set(LOCAL_PROJECT_NAME "C-Sandbox")
set(LOCAL_PROJECT_VERSION "0.0.1")
set(LOCAL_PROJECT_DESCRIPTION "Description")
# Project setup
project(${LOCAL_PROJECT_NAME}
VERSION ${LOCAL_PROJECT_VERSION}
DESCRIPTION ${LOCAL_PROJECT_DESCRIPTION}
LANGUAGES C)
add_executable(${LOCAL_PROJECT_NAME})
target_sources(${LOCAL_PROJECT_NAME} PRIVATE src/main.c)
target_link_options(${LOCAL_PROJECT_NAME} PRIVATE "-specs=nosys.specs")
set_target_properties(${LOCAL_PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "bin")
Edit:
When I cd into my source folder and run arm-none-eabi-gcc main.c -lc "-specs=nosys.specs"
I get no error and an a.out file.