Sunday, April 26, 2020

Build googletest on Mac OS (solve -Werror, -Wc++-extensions)

Build googletest on Mac OS (-Werror, -Wc++-extensions
When I try to build google test on my MacBook using Cmake, the following errors are shown.
**deleted function definitions are a C++11 extension**
**[-Werror,-Wc++11-extensions]**
GTEST_DISALLOW_ASSIGN_(RE);
**error:**
**deleted function definitions are a C++11 extension**
**[-Werror,-Wc++11-extensions]**
...
expanded from macro 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
GTEST_DISALLOW_ASSIGN_(type)
expanded from macro 'GTEST_DISALLOW_ASSIGN_'
type& operator=(type const &) = delete
From the error message, it seems that the compiler is not using the correct C++ standard. Using CMake parameter -DCMAKE_CXX_STANDARD=“17” solves the problem. Below is the full commands
git clone https://github.com/google/googletest
cd googletest/
mkdir build
cd build/
cmake -DCMAKE_CXX_STANDARD="17" ../
make
sudo make install

No comments:

Post a Comment