Unit testing mbed application - c++

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.

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.

Related

Cannot link opencv-3.2.0 when cross compile for beaglebone black

I created a rootfs directory for beaglebone black by chroot and install libopencv-dev for this target.
When I try cross compile with CMAKE_SYSROOT=<rootfs_dir> and link opencv lib to build the app it cannot work.
the toolchain file:
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_CROSSCOMPILING TRUE)
# specify the cross compiler
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
the CMakeLists.txt
set(SRC_FILES helloworld_opencv.cpp)
set(HEADER_FILES helloworld_opencv.hpp)
find_package(OpenCV 3.2.0 EXACT REQUIRED)
add_executable(HelloWorldOpenCV ${SRC_FILES} ${HEADER_FILES})
target_include_directories(HelloWorldOpenCV PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(HelloWorldOpenCV PUBLIC ${OpenCV_LIBS})
install(
FILES ${HEADER_FILES}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
)
install(
TARGETS HelloWorldOpenCV
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
install(
FILES chart.png
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
It found opencv lib in the target rootfs, but the problem here is when I use
target_link_libraries(HelloWorldOpenCV PUBLIC ${OpenCV_LIBS})
It always links some header file from host machine, and when I comment this line it links the header file from target rootfs as I expected
The log when build:
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE SYSROOT: /home/vinhnt/bluesky/../rootfs
-- Found OpenCV: /home/vinhnt/rootfs/usr (found suitable exact version "3.2.0")
-- Found OpenCV
-- OPENCV LIB: opencv_calib3dopencv_coreopencv_features2dopencv_flannopencv_highguiopencv_imgcodecsopencv_imgprocopencv_mlopencv_objdetectopencv_photoopencv_shapeopencv_stitchingopencv_superresopencv_videoopencv_videoioopencv_videostabopencv_vizopencv_arucoopencv_bgsegmopencv_bioinspiredopencv_ccalibopencv_datasetsopencv_dpmopencv_faceopencv_freetypeopencv_fuzzyopencv_hdfopencv_line_descriptoropencv_optflowopencv_phase_unwrappingopencv_plotopencv_regopencv_rgbdopencv_saliencyopencv_stereoopencv_structured_lightopencv_surface_matchingopencv_textopencv_ximgprocopencv_xobjdetectopencv_xphoto
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vinhnt/bluesky/build
Scanning dependencies of target HelloWorldOpenCV
[ 50%] Building CXX object src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/helloworld_opencv.cpp.o
In file included from /usr/arm-linux-gnueabihf/include/c++/7/cstdint:41:0,
from /usr/arm-linux-gnueabihf/include/c++/7/bits/char_traits.h:501,
from /usr/arm-linux-gnueabihf/include/c++/7/ios:40,
from /usr/arm-linux-gnueabihf/include/c++/7/ostream:38,
from /usr/arm-linux-gnueabihf/include/c++/7/iostream:39,
from /home/vinhnt/bluesky/src/helloworld_opencv/helloworld_opencv.cpp:3:
/home/vinhnt/rootfs/usr/include/stdint.h:43:9: error: ‘__int_least8_t’ does not name a type; did you mean ‘__intptr_t’?
typedef __int_least8_t int_least8_t;
^~~~~~~~~~~~~~
__intptr_t
/home/vinhnt/rootfs/usr/include/stdint.h:44:9: error: ‘__int_least16_t’ does not name a type; did you mean ‘__int16_t’?
typedef __int_least16_t int_least16_t;
^~~~~~~~~~~~~~~
__int16_t
/home/vinhnt/rootfs/usr/include/stdint.h:45:9: error: ‘__int_least32_t’ does not name a type; did you mean ‘__int32_t’?
typedef __int_least32_t int_least32_t;
^~~~~~~~~~~~~~~
__int32_t
/home/vinhnt/rootfs/usr/include/stdint.h:46:9: error: ‘__int_least64_t’ does not name a type; did you mean ‘__int64_t’?
typedef __int_least64_t int_least64_t;
^~~~~~~~~~~~~~~
__int64_t
/home/vinhnt/rootfs/usr/include/stdint.h:49:9: error: ‘__uint_least8_t’ does not name a type; did you mean ‘__uintmax_t’?
typedef __uint_least8_t uint_least8_t;
^~~~~~~~~~~~~~~
__uintmax_t
/home/vinhnt/rootfs/usr/include/stdint.h:50:9: error: ‘__uint_least16_t’ does not name a type; did you mean ‘__uint16_t’?
typedef __uint_least16_t uint_least16_t;
^~~~~~~~~~~~~~~~
__uint16_t
/home/vinhnt/rootfs/usr/include/stdint.h:51:9: error: ‘__uint_least32_t’ does not name a type; did you mean ‘__uint32_t’?
typedef __uint_least32_t uint_least32_t;
^~~~~~~~~~~~~~~~
__uint32_t
/home/vinhnt/rootfs/usr/include/stdint.h:52:9: error: ‘__uint_least64_t’ does not name a type; did you mean ‘__uint64_t’?
typedef __uint_least64_t uint_least64_t;
^~~~~~~~~~~~~~~~
__uint64_t
In file included from /usr/arm-linux-gnueabihf/include/c++/7/bits/char_traits.h:501:0,
from /usr/arm-linux-gnueabihf/include/c++/7/ios:40,
from /usr/arm-linux-gnueabihf/include/c++/7/ostream:38,
from /usr/arm-linux-gnueabihf/include/c++/7/iostream:39,
from /home/vinhnt/bluesky/src/helloworld_opencv/helloworld_opencv.cpp:3:
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:58:11: error: ‘::int_least8_t’ has not been declared
using ::int_least8_t;
^~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:59:11: error: ‘::int_least16_t’ has not been declared
using ::int_least16_t;
^~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:60:11: error: ‘::int_least32_t’ has not been declared
using ::int_least32_t;
^~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:61:11: error: ‘::int_least64_t’ has not been declared
using ::int_least64_t;
^~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:76:11: error: ‘::uint_least8_t’ has not been declared
using ::uint_least8_t;
^~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:77:11: error: ‘::uint_least16_t’ has not been declared
using ::uint_least16_t;
^~~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:78:11: error: ‘::uint_least32_t’ has not been declared
using ::uint_least32_t;
^~~~~~~~~~~~~~
/usr/arm-linux-gnueabihf/include/c++/7/cstdint:79:11: error: ‘::uint_least64_t’ has not been declared
using ::uint_least64_t;
^~~~~~~~~~~~~~
src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/build.make:62: recipe for target 'src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/helloworld_opencv.cpp.o' failed
make[2]: *** [src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/helloworld_opencv.cpp.o] Error 1
CMakeFiles/Makefile2:103: recipe for target 'src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/all' failed
make[1]: *** [src/helloworld_opencv/CMakeFiles/HelloWorldOpenCV.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
anyone got this problem, please help me!

CMake `test_big_endian` failed with `no suitable type found`

gcc (GCC) 10.2.0
cmake version 3.19.4
CMakeFile.txt
...
test_big_endian(WORDS_BIGENDIAN)
...
cmake output:
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - not found
-- Looking for stdint.h
-- Looking for stdint.h - not found
-- Looking for stddef.h
-- Looking for stddef.h - not found
-- Check size of unsigned short
-- Check size of unsigned short - failed
-- Check size of unsigned int
-- Check size of unsigned int - failed
-- Check size of unsigned long
-- Check size of unsigned long - failed CMake Error at /usr/local/cmake/share/cmake-3.19/Modules/TestBigEndian.cmake:51
(message): no suitable type found Call Stack (most recent call
first): contrib/xz/cmake/tuklib_integer.cmake:23 (test_big_endian)
contrib/xz/CMakeLists.txt:126 (tuklib_integer)
CMakeError.log output:
Determining if the include file sys/types.h exists failed with the following output:
Change Dir: /data/clickhouse/clickhouse/ClickHouse/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/local/bin/ninja cmTC_73c6f && [1/2] Building C object CMakeFiles/cmTC_73c6f.dir/CheckIncludeFile.c.o
[2/2] Linking C executable cmTC_73c6f
FAILED: cmTC_73c6f
: && /usr/local/bin/gcc -fdiagnostics-color=always -pipe -msse4.1 -msse4.2 -mpopcnt -Wall -Werror -w -fuse-ld=gold -rdynamic -Wl,--no-undefined -Wl,-no-pie -rdynamic CMakeFiles/cmTC_73c6f.dir/CheckIncludeFile.c.o -o cmTC_73c6f && :
/usr/bin/ld.gold: error: cannot find -lgcc_s
/usr/bin/ld.gold: error: cannot find -lgcc_s
/lib/../lib64/libc.a(syslog.o):function __vsyslog_chk: error: undefined reference to '_Unwind_Resume'
/lib/../lib64/libc.a(syslog.o):function __vsyslog_chk: error: undefined reference to '_Unwind_Resume'
/lib/../lib64/libc.a(syslog.o):function openlog: error: undefined reference to '_Unwind_Resume'
/lib/../lib64/libc.a(syslog.o):function closelog: error: undefined reference to '_Unwind_Resume'
/lib/../lib64/libc.a(syslog.o)(.eh_frame+0xd78b): error: undefined reference to '__gcc_personality_v0'
/lib/../lib64/libc.a(backtrace.o):function backtrace_helper: error: undefined reference to '_Unwind_GetIP'
/lib/../lib64/libc.a(backtrace.o):function backtrace_helper: error: undefined reference to '_Unwind_GetCFA'
/lib/../lib64/libc.a(backtrace.o):function __backtrace: error: undefined reference to '_Unwind_Backtrace'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
I found where the error occurred.
cmake-3.19/Modules/CheckIncludeFile.cmake:
if(${VARIABLE})
if(NOT CMAKE_REQUIRED_QUIET)
message(CHECK_PASS "found")
endif()
set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the include file ${INCLUDE} "
"exists passed with the following output:\n"
"${OUTPUT}\n\n")
else()
if(NOT CMAKE_REQUIRED_QUIET)
message(CHECK_FAIL "not found")
endif()
set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the include file ${INCLUDE} "
"exists failed with the following output:\n"
"${OUTPUT}\n\n")
endif()
What does the error mean? How to fix it?
---- new ----
/usr/bin/ld.gold: error: cannot find -lgcc_s cause by gcc flag -Wl,-no-pie. Why gcc_s can not found?
Btw in cmake 3.20 they introduced CMAKE_LANG_BYTE_ORDER.
Which is faster than using TestBigEndian: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_BYTE_ORDER.html#variable:CMAKE_%3CLANG%3E_BYTE_ORDER
The reason was version of ld too low (2.23). Updated to version (2.27), it works fine.

CMake: unsupported GNU version -- gcc versions later than 8 are not supported

Before downgrading my GCC, I want to know if there's a way to figure which programs/frameworks or dependencies in my machine will break and if there is a better way to do this for openpose installation? (e.g. changing something in CMake)
Is there a hack to fix this without changing my system GCC version and potentially breaking other things?
[10889:10881 0:2009] 09:21:36 Wed Jan 06 [mona#goku:pts/0 +1] ~/research/code/openpose/build
$ make -j`nproc`
[ 12%] Performing configure step for 'openpose_lib'
CMake Warning (dev) at cmake/Misc.cmake:32 (set):
implicitly converting 'BOOLEAN' to 'STRING' type.
Call Stack (most recent call first):
CMakeLists.txt:25 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Found gflags (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libgflags.so)
-- Found glog (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libglog.so)
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5: Using hdf5 compiler wrapper to determine CXX configuration
-- CUDA detected: 10.1
-- Added CUDA NVCC flags for: sm_75
-- Found Atlas: /usr/include/x86_64-linux-gnu
-- Found Atlas (include: /usr/include/x86_64-linux-gnu library: /usr/lib/x86_64-linux-gnu/libatlas.so lapack: /usr/lib/x86_64-linux-gnu/liblapack.so
-- Python interface is disabled or not all required dependencies found. Building without it...
-- Found Git: /usr/bin/git (found version "2.25.1")
--
-- ******************* Caffe Configuration Summary *******************
-- General:
-- Version : 1.0.0
-- Git : 1.0-149-g1807aada
-- System : Linux
-- C++ compiler : /usr/bin/c++
-- Release CXX flags : -O3 -DNDEBUG -fPIC -Wall -std=c++11 -Wno-sign-compare -Wno-uninitialized
-- Debug CXX flags : -g -fPIC -Wall -std=c++11 -Wno-sign-compare -Wno-uninitialized
-- Build type : Release
--
-- BUILD_SHARED_LIBS : ON
-- BUILD_python : OFF
-- BUILD_matlab : OFF
-- BUILD_docs : OFF
-- CPU_ONLY : OFF
-- USE_OPENCV : OFF
-- USE_LEVELDB : OFF
-- USE_LMDB : OFF
-- USE_NCCL : OFF
-- ALLOW_LMDB_NOLOCK : OFF
-- USE_HDF5 : ON
--
-- Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.71)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 3.6.1)
-- CUDA : Yes (ver. 10.1)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_75
-- cuDNN : Disabled
--
-- Install:
-- Install path : /home/mona/research/code/openpose/build/caffe
--
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CUDA_ARCH_BIN
-- Build files have been written to: /home/mona/research/code/openpose/build/caffe/src/openpose_lib-build
[ 25%] Performing build step for 'openpose_lib'
[ 1%] Running C++/Python protocol buffer compiler on /home/mona/research/code/openpose/3rdparty/caffe/src/caffe/proto/caffe.proto
Scanning dependencies of target caffeproto
[ 1%] Building CXX object src/caffe/CMakeFiles/caffeproto.dir/__/__/include/caffe/proto/caffe.pb.cc.o
[ 1%] Linking CXX static library ../../lib/libcaffeproto.a
[ 1%] Built target caffeproto
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/util/cuda_compile_1_generated_math_functions.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bnll_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_accuracy_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_reindex_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_norm_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bias_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_base_data_layer.cu.o
[ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_concat_layer.cu.o
[ 5%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_clip_layer.cu.o
[ 6%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o
[ 6%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_conv_layer.cu.o
[ 6%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_contrastive_loss_layer.cu.o
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
In file included from /home/mona/research/code/openpose/3rdparty/caffe/src/caffe/util/math_functions.cu:1:
/usr/include/math_functions.h:54:2: warning: #warning "math_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release. Please use cuda_runtime_api.h or cuda_runtime.h instead." [-Wcpp]
54 | #warning "math_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release. Please use cuda_runtime_api.h or cuda_runtime.h instead."
| ^~~~~~~
CMake Error at cuda_compile_1_generated_clip_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_clip_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:114: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_clip_layer.cu.o] Error 1
make[5]: *** Waiting for unfinished jobs....
CMake Error at cuda_compile_1_generated_absval_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_absval_layer.cu.o
CMake Error at cuda_compile_1_generated_concat_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_concat_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:65: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o] Error 1
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:121: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_concat_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_batch_reindex_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_batch_reindex_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:93: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_reindex_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_bias_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_bias_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:100: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bias_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_batch_norm_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_batch_norm_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:86: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_norm_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_contrastive_loss_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_contrastive_loss_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:128: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_contrastive_loss_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_conv_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_conv_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:135: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_conv_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_accuracy_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_accuracy_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:72: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_accuracy_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_base_data_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_base_data_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:79: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_base_data_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_bnll_layer.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_bnll_layer.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:107: src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bnll_layer.cu.o] Error 1
CMake Error at cuda_compile_1_generated_math_functions.cu.o.Release.cmake:220 (message):
Error generating
/home/mona/research/code/openpose/build/caffe/src/openpose_lib-build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/./cuda_compile_1_generated_math_functions.cu.o
make[5]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:499: src/caffe/CMakeFiles/cuda_compile_1.dir/util/cuda_compile_1_generated_math_functions.cu.o] Error 1
make[4]: *** [CMakeFiles/Makefile2:371: src/caffe/CMakeFiles/caffe.dir/all] Error 2
make[3]: *** [Makefile:130: all] Error 2
make[2]: *** [CMakeFiles/openpose_lib.dir/build.make:112: caffe/src/openpose_lib-stamp/openpose_lib-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/openpose_lib.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
21834/31772MB(openpose)
[10889:10881 0:2010] 09:21:55 Wed Jan 06 [mona#goku:pts/0 +1] ~/research/code/openpose/build
$
I have:
$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 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.
I am following the compilation instructions here on Ubuntu 20.04:
https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation/README.md#prerequisites
Solved by downgrading the GCC from 9.3.0 to 7:
$ sudo apt remove gcc
$ sudo apt-get install gcc-7 g++-7 -y
$ sudo ln -s /usr/bin/gcc-7 /usr/bin/gcc
$ sudo ln -s /usr/bin/g++-7 /usr/bin/g++
$ sudo ln -s /usr/bin/gcc-7 /usr/bin/cc
$ sudo ln -s /usr/bin/g++-7 /usr/bin/c++
$ gcc --version
gcc (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 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.
You should point to a correct GCC bin file (below 9) from the dependencies in cmake command. no need to downgrade the GCC for example:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8

Failing to compile a c++ application under MacOS Catalina 10.15

Note: For how I solved the problem, please look at the end of the post.
Yesterday, I have updated to MacOS Catalina 10.15 and since then I am trying to compile this c++ application (a fork of the nori educational ray tracer), but for some reason CMake fails to find the pthread library. Here is the output after running CMake:
$ cmake ..
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- Performing Test HAS_CPP11_FLAG
-- Performing Test HAS_CPP11_FLAG - Success
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.11")
-- Performing Test HAVE_GCC_INLINE_ASM_AVX
-- Performing Test HAVE_GCC_INLINE_ASM_AVX - Failed
-- Performing Test HAVE_SYSCONF_NPROCESSORS_ONLN
-- Performing Test HAVE_SYSCONF_NPROCESSORS_ONLN - Failed
-- TBB: NOT using libc++.
-- Looking for pthread.h
-- Looking for pthread.h - not found
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/Applications/CMake.app/Contents/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/Applications/CMake.app/Contents/share/cmake-3.15/Modules/FindThreads.cmake:220 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
ext/nanogui/ext/glfw/CMakeLists.txt:60 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/harry/dev/nori/build/CMakeFiles/CMakeOutput.log".
See also "/Users/harry/dev/nori/build/CMakeFiles/CMakeError.log".
And following is the CMakeError.log:
Performing C++ SOURCE FILE Test HAVE_GCC_INLINE_ASM_AVX failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_1e411/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_1e411.dir/build.make CMakeFiles/cmTC_1e411.dir/build
Building CXX object CMakeFiles/cmTC_1e411.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++14 -fvisibility=hidden -Wno-switch -Wno-tautological-compare -Wno-deprecated-register -DHAVE_GCC_INLINE_ASM_AVX -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -o CMakeFiles/cmTC_1e411.dir/src.cxx.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/src.cxx
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: warning: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Wincompatible-sysroot]
make[1]: *** [CMakeFiles/cmTC_1e411.dir/src.cxx.o] Error 1
make: *** [cmTC_1e411/fast] Error 2
Source file was:
int main()
{
#if defined(__GNUC__) && defined(__SSE2__)
int n = 0;
int eax = 0;
int edx = 0;
__asm__(
"xgetbv ;"
"vzeroupper "
: "=a"(eax), "=d"(edx) : "c"(n) : );
#else
#error No GCC style inline asm supported for AVX instructions
#endif
}
Performing C++ SOURCE FILE Test HAVE_SYSCONF_NPROCESSORS_ONLN failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_db06f/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_db06f.dir/build.make CMakeFiles/cmTC_db06f.dir/build
Building CXX object CMakeFiles/cmTC_db06f.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++14 -fvisibility=hidden -Wno-switch -Wno-tautological-compare -Wno-deprecated-register -DHAVE_SYSCONF_NPROCESSORS_ONLN -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -o CMakeFiles/cmTC_db06f.dir/src.cxx.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/src.cxx
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: warning: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Wincompatible-sysroot]
make[1]: *** [CMakeFiles/cmTC_db06f.dir/src.cxx.o] Error 1
make: *** [cmTC_db06f/fast] Error 2
Source file was:
#include <unistd.h>
int main()
{
sysconf(_SC_NPROCESSORS_ONLN);
}
Performing C++ SOURCE FILE Test HAS_LIBCPP failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_4098b/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_4098b.dir/build.make CMakeFiles/cmTC_4098b.dir/build
Building CXX object CMakeFiles/cmTC_4098b.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++14 -fvisibility=hidden -DHAS_LIBCPP -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -o CMakeFiles/cmTC_4098b.dir/src.cxx.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/src.cxx
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: warning: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Wincompatible-sysroot]
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
make[1]: *** [CMakeFiles/cmTC_4098b.dir/src.cxx.o] Error 1
make: *** [cmTC_4098b/fast] Error 2
...and run output:
Return value: 1
Source file was:
#include <iostream>
int main(int argc, char **argv) { std::cout << "test"; return 0; }
Performing C++ SOURCE FILE Test SUPPORTS_STDCXX11 failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_74f47/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_74f47.dir/build.make CMakeFiles/cmTC_74f47.dir/build
Building CXX object CMakeFiles/cmTC_74f47.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++14 -fvisibility=hidden -DSUPPORTS_STDCXX11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -std=c++11 -o CMakeFiles/cmTC_74f47.dir/src.cxx.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/src.cxx
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: warning: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Wincompatible-sysroot]
make[1]: *** [CMakeFiles/cmTC_74f47.dir/src.cxx.o] Error 1
make: *** [cmTC_74f47/fast] Error 2
Source file was:
int main() { return 0; }
Performing C++ SOURCE FILE Test SUPPORTS_MRTM failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_60b35/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_60b35.dir/build.make CMakeFiles/cmTC_60b35.dir/build
Building CXX object CMakeFiles/cmTC_60b35.dir/src.cxx.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++14 -fvisibility=hidden -DSUPPORTS_MRTM -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mrtm -Werror -o CMakeFiles/cmTC_60b35.dir/src.cxx.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/src.cxx
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: error: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Werror,-Wincompatible-sysroot]
make[1]: *** [CMakeFiles/cmTC_60b35.dir/src.cxx.o] Error 1
make: *** [cmTC_60b35/fast] Error 2
Source file was:
int main() { return 0; }
Determining if the include file pthread.h exists failed with the following output:
Change Dir: /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_b4d5d/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_b4d5d.dir/build.make CMakeFiles/cmTC_b4d5d.dir/build
Building C object CMakeFiles/cmTC_b4d5d.dir/CheckIncludeFile.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -Wno-deprecated-declarations -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk -o CMakeFiles/cmTC_b4d5d.dir/CheckIncludeFile.c.o -c /Users/harry/dev/nori/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
clang: warning: using sysroot for 'DriverKit' but targeting 'MacOSX' [-Wincompatible-sysroot]
make[1]: *** [CMakeFiles/cmTC_b4d5d.dir/CheckIncludeFile.c.o] Error 1
make: *** [cmTC_b4d5d/fast] Error 2
The nori ray tracer expects XCode along with the command line tools installed on a MacOS machine. I have Xcode version 11.1 and the corresponding command line tools.
As far as I can see from the CMakeError.log file, clang produces an error, because of an invalid version number of mmacosx-version-min.
clang: error: invalid version number in '-mmacosx-version-min=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk'
I have researched a while trying to find clues on the topic, but failed to find something that solves my problem. The version of clang I have, is the one installed with Xcode: Apple clang version 11.0.0.
I am open to hear any suggestion and provide any additional information on my configuration you may find useful to pinpoint the issue.
P.S.: I forgot to mention, that back when I first started working on this project, I had a similar issue on MacOS Mojave here. And I was able to fix it by installing the SDK headers as noted in this post:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Working solution: Installing an older version of XCode (10.2.1 works well for me) and redirecting to it (making it the active developer directory with xcode-select -s [path-to-old-xcode]) turns out to solve my problem. The solution was proposed by Aaron19960821 from GitHub. See here.

Can I install raspicam c++ libraries on OS X?

I'm developing an OpenCV project that will run on a raspberry pi. So far I have been developing on a Mac in Xcode and all is going well. I recently realized that in order to tap into the raspberry pi camera I will need to use the raspicam library.
My question is, can I install raspicam libraries on OS X or are they raspberry pi hardware specific?
I would like to be able to develop, compile, and build on my Mac as well as compile and build on the raspberry pi. I am trying to avoid doing my development on the Pi.
If that's not possible do you have any recommendations for how I should manage the development setup for this project?
There is only a small section of my code that requires the raspicam libraries so I am not opposed to having a flag that executes the raspicam code if running on the Pi, otherwise executes the currently working OpenCV code if running on the Mac.
So far I have downloaded the raspicam source and I have done:
cd raspicam-0.1.3
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV" ..
And here is the output:
-- Adding cv library
--
-- -------------------------------------------------------------------------------
-- General configuration for raspicam 0.1.2
-- -------------------------------------------------------------------------------
--
Built as dynamic libs?:ON
Compiler:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- C++ flags (Release): -std=c++0x -Wl,--no-as-needed -lpthread
-- C++ flags (Debug): -std=c++0x -Wl,--no-as-needed -lpthread
-- CMAKE_CXX_FLAGS: -std=c++0x -Wl,--no-as-needed
-- CMAKE_BINARY_DIR: /Users/andres/Downloads/raspicam-0.1.3/build
--
-- CMAKE_SYSTEM_PROCESSOR = x86_64
-- BUILD_SHARED_LIBS = ON
-- BUILD_UTILS = ON
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_BUILD_TYPE = Release
-- CMAKE_MODULE_PATH = /usr/local/lib/cmake/;/usr/lib/cmake
--
-- CREATE OPENCV MODULE=1
-- CMAKE_INSTALL_PREFIX=/usr/local
-- REQUIRED_LIBRARIES=
--
--
-- Change a value with: cmake -D<Variable>=<Value>
--
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
raspicam
raspicam_cv
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/andres/Downloads/raspicam-0.1.3/build
Then
make
Output:
Scanning dependencies of target raspicam_cv
[ 5%] Building CXX object src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o
clang: warning: -Wl,--no-as-needed: 'linker' input unused
clang: warning: -lpthread: 'linker' input unused
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:297:22: error:
use of undeclared identifier 'CLOCK_REALTIME'
if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
^
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:307:13: error:
use of undeclared identifier 'sem_timedwait'
ret = sem_timedwait( sem, &ts );
^
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:327:13: warning:
'sem_init' is deprecated [-Wdeprecated-declarations]
int rc = sem_init(sem, 0, initial_count);
^
/usr/include/sys/semaphore.h:55:5: note: 'sem_init' has been explicitly marked
deprecated here
int sem_init(sem_t *, int, unsigned int) __deprecated;
^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:335:13: warning:
'sem_destroy' is deprecated [-Wdeprecated-declarations]
int rc = sem_destroy(sem);
^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
marked deprecated here
int sem_destroy(sem_t *) __deprecated;
^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:520:13: warning:
'sem_init' is deprecated [-Wdeprecated-declarations]
int rc = sem_init(&event->sem, 0, 0);
^
/usr/include/sys/semaphore.h:55:5: note: 'sem_init' has been explicitly marked
deprecated here
int sem_init(sem_t *, int, unsigned int) __deprecated;
^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:525:7: warning:
'sem_destroy' is deprecated [-Wdeprecated-declarations]
sem_destroy(&event->sem);
^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
marked deprecated here
int sem_destroy(sem_t *) __deprecated;
^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:541:8: warning:
'sem_getvalue' is deprecated [-Wdeprecated-declarations]
if (sem_getvalue(&event->sem, &value) != 0)
^
/usr/include/sys/semaphore.h:54:5: note: 'sem_getvalue' has been explicitly
marked deprecated here
int sem_getvalue(sem_t * __restrict, int * __restrict) __deprecated;
^
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/raspicam_cv.cpp:39:
In file included from /Users/andres/Downloads/raspicam-0.1.3/src/./private/private_impl.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal.h:363:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/mmal/mmal_common.h:40:
In file included from /Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/vcos.h:116:
/Users/andres/Downloads/raspicam-0.1.3/dependencies/vcos/pthreads/vcos_platform.h:582:13: warning:
'sem_destroy' is deprecated [-Wdeprecated-declarations]
int rc = sem_destroy(&event->sem);
^
/usr/include/sys/semaphore.h:53:5: note: 'sem_destroy' has been explicitly
marked deprecated here
int sem_destroy(sem_t *) __deprecated;
^
6 warnings and 2 errors generated.
make[2]: *** [src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/raspicam_cv.dir/all] Error 2
make: *** [all] Error 2
The solution I came up with was to use:
#ifdef __ARM__
include <raspicam/raspicam.h>
#endif
and in the main
#ifdef __ARM__
// pi specific camera initialization code
#elif __APPLE__
// osx specific camera initialization code
#endif
These preprocessors will be evaluated before the code is compiled. If the source is being compiled on the pi (ARM architecture) the __ARM__ sections will be compiled, otherwise if the source code is being compiled on osx the __APPLE__ sections will be compiled.