Issue
I'm working on an mbed application and I want to be able to unit test some of the functionality. I created a test app so I could try out unit testing and I can't seem to get it to build. The TLDR of it is when I go to build the app the build fails with errors like:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_core_c.h:42:2: error: #error "Unknown Arm Architecture!"
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2015:40: error: 'fileno' was not declared in this scope; did you mean 'file'?
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2021:47: error: 'strdup' was not declared in this scope; did you mean 'StrDup'?
The more detailed version of it, on Windows I created a new app by:
1. mbed-tools new
2. mbed-tools configure -m K64F -t GCC_ARM
Then I created a simple class to be tested MyClass.h
and MyClass.cpp
#include "MyClass.h"
MyClass::MyClass() { }
bool MyClass::IsTwo(int number) {
return number == 2;
}
And then also a simple test file UNITTESTS\test_MyClass.cc
#include "gtest/gtest.h"
#include "../MyClass.h"
class TestMyClass : public testing::Test {
protected:
MyClass *cls;
void SetUp(){
cls = new MyClass();
}
void TearDown(){
delete cls;
}
};
TEST_F(TestMyClass, test_isTwo){
EXPECT_TRUE(cls->IsTwo(2));
EXPECT_FALSE(cls->IsTwo(23));
}
Then following the instructions from Google found here I edited my root CMakeList.txt
to be
# Copyright (c) 2022 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.19.0)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET gtest_example)
include(${MBED_PATH}/tools/cmake/app.cmake)
project(${APP_TARGET})
# Disable tests as default configuration, use -DBUILD_TESTING to enable
option(BUILD_TESTING "Run mbed os UNITTESTS" ON)
add_subdirectory(${MBED_PATH})
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(${MBED_PATH}/UNITTESTS) # add mbed os stubs and fakes
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/UNITTESTS)
endif()
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
# For Windows: Prevent overriding the parent projects compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_executable(${APP_TARGET}
main.cpp
MyClass.cpp MyClass.h
)
target_link_libraries(${APP_TARGET} mbed-os)
mbed_set_post_build(${APP_TARGET})
option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
and the UNITTESTS\CMakeLists.txt
file to be
set(TEST_NAME example-unittest)
enable_testing()
add_executable(${TEST_NAME}
test_MyClass.cc
)
target_link_libraries(${TEST_NAME}
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(${TEST_NAME})
Then I ran
cmake -S . -B cmake_build\K64F\develop\GCC_ARM -GNinja -DBUILD_TESTING=ON -DCMAKE_CXX_FLAGS=-std=c++14
resulting in
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: C:/Python39/python.exe (found version "3.9.7") found components: Interpreter
-- Checking for Python package prettytable -- found
-- Checking for Python package future -- found
-- Checking for Python package jinja2 -- found
-- Checking for Python package intelhex -- found
-- Found Python: C:/Python39/python.exe (found version "3.9.7") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find Threads (missing: Threads_FOUND)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM
and then finally I ran
cmake --build cmake_build\K64F\develop\GCC_ARM
which fails with a bunch of errors
[75/208] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
FAILED: _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @_deps\googletest-build\googletest\CMakeFiles\gtest_main.dir\src\gtest_main.cc.obj.rsp -MD -MT _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -MF _deps\googletest-build\googletest\CMakeFiles\gtest_main.dir\src\gtest_main.cc.obj.d -o _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -c C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/src/gtest_main.cc
In file included from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/gtest-message.h:55,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/gtest-assertion-result.h:46,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/gtest.h:59,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/src/gtest_main.cc:32:
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2015:40: error: 'fileno' was not declared in this scope; did you mean 'file'?
2015 | inline int FileNo(FILE* file) { return fileno(file); }
| ^~~~~~
| file
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2021:47: error: 'strdup' was not declared in this scope; did you mean 'StrDup'?
2021 | inline char* StrDup(const char* src) { return strdup(src); }
| ^~~~~~
| StrDup
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2065:56: error: 'fdopen' was not declared in this scope; did you mean 'fopen'?
2065 | inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
| ^~~~~~
| fopen
[77/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\cmsis\device\rtos\source\mbed_rtx_idle.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\cmsis\device\rtos\source\mbed_rtx_idle.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/internal/SysTimer.h:21,
from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/internal/mbed_os_timer.h:21,
from C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp:27:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_lib.h:31,
from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/internal/mbed_os_timer.h:25,
from C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/device/rtos/source/mbed_rtx_idle.cpp:27:
C:/Users/chris/Desktop/gtest_example/mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_core_c.h:42:2: error: #error "Unknown Arm Architecture!"
42 | #error "Unknown Arm Architecture!"
| ^~~~~
[78/208] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj
FAILED: _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @_deps\googletest-build\googlemock\CMakeFiles\gmock_main.dir\src\gmock_main.cc.obj.rsp -MD -MT _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj -MF _deps\googletest-build\googlemock\CMakeFiles\gmock_main.dir\src\gmock_main.cc.obj.d -o _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj -c C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/src/gmock_main.cc
In file included from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/internal/gmock-port.h:57,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/internal/gmock-internal-utils.h:49,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:145,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/gmock.h:56,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/src/gmock_main.cc:32:
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2015:40: error: 'fileno' was not declared in this scope; did you mean 'file'?
2015 | inline int FileNo(FILE* file) { return fileno(file); }
| ^~~~~~
| file
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2021:47: error: 'strdup' was not declared in this scope; did you mean 'StrDup'?
2021 | inline char* StrDup(const char* src) { return strdup(src); }
| ^~~~~~
| StrDup
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2065:56: error: 'fdopen' was not declared in this scope; did you mean 'fopen'?
2065 | inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
| ^~~~~~
| fopen
[79/208] Building CXX object CMakeFiles/gtest_example.dir/main.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/main.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\main.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/main.cpp.obj -MF CMakeFiles\gtest_example.dir\main.cpp.obj.d -o CMakeFiles/gtest_example.dir/main.cpp.obj -c C:/Users/chris/Desktop/gtest_example/main.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\analogin.h:25,
from C:/Users/chris/Desktop/gtest_example/mbed-os/mbed.h:63,
from C:/Users/chris/Desktop/gtest_example/main.cpp:6:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/mbed.h:75,
from C:/Users/chris/Desktop/gtest_example/main.cpp:6:
c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\mbedcrc.h:658:2: error: #error "Unknown ARM architecture for CRC optimization"
658 | #error "Unknown ARM architecture for CRC optimization"
| ^~~~~
[80/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/AnalogIn.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/AnalogIn.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\AnalogIn.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/AnalogIn.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\AnalogIn.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/AnalogIn.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/AnalogIn.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\analogin.h:25,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/AnalogIn.cpp:18:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[81/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SerialBase.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SerialBase.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\SerialBase.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SerialBase.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\SerialBase.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SerialBase.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/SerialBase.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_wait_api.h:21,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/SerialBase.cpp:18:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[82/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/FlashIAP.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/FlashIAP.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\FlashIAP.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/FlashIAP.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\FlashIAP.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/FlashIAP.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/FlashIAP.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\flashiap.h:30,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/FlashIAP.cpp:28:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[83/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/platform/cxxsupport/mstd_mutex.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/platform/cxxsupport/mstd_mutex.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\platform\cxxsupport\mstd_mutex.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/platform/cxxsupport/mstd_mutex.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\platform\cxxsupport\mstd_mutex.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/platform/cxxsupport/mstd_mutex.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/platform/cxxsupport/mstd_mutex.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\platform\cxxsupport\mstd_mutex:43,
from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/cxxsupport/mstd_mutex.cpp:18:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[84/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/I2C.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/I2C.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\I2C.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/I2C.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\I2C.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/I2C.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/I2C.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\i2c.h:26,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/I2C.cpp:18:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[85/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/MbedCRC.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/MbedCRC.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\MbedCRC.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/MbedCRC.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\MbedCRC.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/MbedCRC.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/MbedCRC.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\mbedcrc.h:29,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/MbedCRC.cpp:19:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/MbedCRC.cpp:19:
c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\mbedcrc.h:658:2: error: #error "Unknown ARM architecture for CRC optimization"
658 | #error "Unknown ARM architecture for CRC optimization"
| ^~~~~
[86/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/platform/source/DeepSleepLock.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/platform/source/DeepSleepLock.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\platform\source\DeepSleepLock.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/platform/source/DeepSleepLock.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\platform\source\DeepSleepLock.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/platform/source/DeepSleepLock.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/platform/source/DeepSleepLock.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/source/DeepSleepLock.cpp:20:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[87/208] Building CXX object CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SPI.cpp.obj
FAILED: CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SPI.cpp.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @CMakeFiles\gtest_example.dir\mbed-os\drivers\source\SPI.cpp.obj.rsp -MD -MT CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SPI.cpp.obj -MF CMakeFiles\gtest_example.dir\mbed-os\drivers\source\SPI.cpp.obj.d -o CMakeFiles/gtest_example.dir/mbed-os/drivers/source/SPI.cpp.obj -c C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/SPI.cpp
In file included from C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/SingletonPtr.h:24,
from c:\users\chris\desktop\gtest_example\mbed-os\drivers\include\drivers\spi.h:27,
from C:/Users/chris/Desktop/gtest_example/mbed-os/drivers/source/SPI.cpp:17:
C:/Users/chris/Desktop/gtest_example/mbed-os/platform/include/platform/mbed_atomic.h:95:2: error: #error "Unknown ARM architecture for exclusive access"
95 | #error "Unknown ARM architecture for exclusive access"
| ^~~~~
[88/208] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj
FAILED: _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj
C:\ProgramData\chocolatey\bin\ccache.exe C:\PROGRA~2\GNUARM~1\102021~1.10\bin\AR10B2~1.EXE @_deps\googletest-build\googlemock\CMakeFiles\gmock.dir\src\gmock-all.cc.obj.rsp -MD -MT _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj -MF _deps\googletest-build\googlemock\CMakeFiles\gmock.dir\src\gmock-all.cc.obj.d -o _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj -c C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/src/gmock-all.cc
In file included from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/internal/gmock-port.h:57,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/internal/gmock-internal-utils.h:49,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:145,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/include/gmock/gmock.h:56,
from C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googlemock/src/gmock-all.cc:39:
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2015:40: error: 'fileno' was not declared in this scope; did you mean 'file'?
2015 | inline int FileNo(FILE* file) { return fileno(file); }
| ^~~~~~
| file
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2021:47: error: 'strdup' was not declared in this scope; did you mean 'StrDup'?
2021 | inline char* StrDup(const char* src) { return strdup(src); }
| ^~~~~~
| StrDup
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
C:/Users/chris/Desktop/gtest_example/cmake_build/K64F/develop/GCC_ARM/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2065:56: error: 'fdopen' was not declared in this scope; did you mean 'fopen'?
2065 | inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
| ^~~~~~
| fopen
...
ninja: build stopped: subcommand failed.
Solution
If I see this correctly, you are basically trying to use ARM cross compiler to create an x86(_64) test application. Mixing those two can't work. Hence the root cause of your problems "Unknown ARM architecture for exclusive access"
.
What you need is a CMake project capable targetting multiple platforms - ARM for embedded target and x86 for unit tests. -DBUILD_TESTING
switch you already use is a good one to distinguish between ARM and x86 toolchains in the CMake.
I would suggest to separate the building stage from the main project directory. Create a subdirectory named x86
and call cmake .. -DDBUILD_TESTING
for unit tests. Please note the ..
instead of .
in the command.
Then create another directory arm
and call cmake ..
for cross compiling the target objects for ARM. Add additional cmake parameters to both as needed.
You need to use native Windows compiler instead of a ARM cross compiler for the unit tests to work.
Answered By - Thinkeye Answer Checked By - Marilyn (WPSolving Volunteer)