Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building tests fails with gtest 1.14.0: error C++ versions less than C++14 are not supported #44

Closed
badshah400 opened this issue Apr 25, 2024 · 6 comments · Fixed by #46

Comments

@badshah400
Copy link

Builds for ade (version 0.1.2d) are currently failing for openSUSE Tumbleweed when building tests using system installed gtest which is at version 1.14.0. This version of gtest requires at least whereas ade seems to enforce CMAKE_CXX_STANDARD=11 and passing -DCMAKE_CXX_STANDARD=14 when calling cmake does not help either.

Here is the relevant portion of the failing build log:

[   48s] + /usr/bin/cmake /home/abuild/rpmbuild/BUILD/ade-0.1.2d/. '-GUnix Makefiles' -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_BINDIR:PATH=bin -DCMAKE_INSTALL_SBINDIR:PATH=sbin -DCMAKE_INSTALL_LIBEXECDIR:PATH=libexec -DCMAKE_INSTALL_SYSCONFDIR:PATH=etc -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=/var/lib -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=var -DCMAKE_INSTALL_RUNSTATEDIR:PATH=run -DCMAKE_INSTALL_LIBDIR:PATH=lib64 -DCMAKE_INSTALL_INCLUDEDIR:PATH=include -DCMAKE_INSTALL_DATAROOTDIR:PATH=share -DCMAKE_INSTALL_DOCDIR:PATH=share/doc/packages/ade -DCMAKE_INSTALL_MANDIR:PATH=share/man -DCMAKE_INSTALL_INFODIR:PATH=share/info -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DCMAKE_BUILD_TYPE=RelWithDebInfo '-DCMAKE_C_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -ffat-lto-objects -g' '-DCMAKE_CXX_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -ffat-lto-objects -g' '-DCMAKE_Fortran_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -ffat-lto-objects -g' '-DCMAKE_EXE_LINKER_FLAGS=-flto=auto -ffat-lto-objects -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now' '-DCMAKE_MODULE_LINKER_FLAGS=-flto=auto -ffat-lto-objects -Wl,--as-needed' '-DCMAKE_SHARED_LINKER_FLAGS=-flto=auto -ffat-lto-objects -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now' -DLIB_SUFFIX=64 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_STATIC_LIBS:BOOL=OFF -DCMAKE_COLOR_MAKEFILE:BOOL=OFF -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF -DCMAKE_MODULES_INSTALL_DIR=/usr/lib64/cmake/ade -DCMAKE_CXX_STANDARD=14 -DGTEST_ROOT:PATH=/usr -DENABLE_ADE_TESTING=ON

---✀---

[   54s] [ 50%] Building CXX object sources/tests/common/CMakeFiles/common-tests.dir/checkedcast_test.cpp.o
[   54s] cd /home/abuild/rpmbuild/BUILD/ade-0.1.2d/build/sources/tests/common && /var/lib/build/ccache/bin/c++ -D_FORTIFY_SOURCE=2 -I/home/abuild/rpmbuild/BUILD/ade-0.1.2d/sources/ade/include -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -ffat-lto-objects -g -O2 -g -DNDEBUG -std=gnu++11 -fstack-protector-strong -MD -MT sources/tests/common/CMakeFiles/common-tests.dir/checkedcast_test.cpp.o -MF CMakeFiles/common-tests.dir/checkedcast_test.cpp.o.d -o CMakeFiles/common-tests.dir/checkedcast_test.cpp.o -c /home/abuild/rpmbuild/BUILD/ade-0.1.2d/sources/tests/common/checkedcast_test.cpp
[   54s] In file included from /usr/include/gtest/gtest-message.h:57,
[   54s]                  from /usr/include/gtest/gtest-assertion-result.h:46,
[   54s]                  from /usr/include/gtest/gtest.h:64,
[   54s]                  from /home/abuild/rpmbuild/BUILD/ade-0.1.2d/sources/tests/common/checkedcast_test.cpp:12:
[   54s] /usr/include/gtest/internal/gtest-port.h:279:2: error: #error C++ versions less than C++14 are not supported.
[   54s]   279 | #error C++ versions less than C++14 are not supported.
[   54s]       |  ^~~~~
[   54s] /usr/include/gtest/gtest-assertion-result.h: In member function ‘void testing::AssertionResult::AppendMessage(const testing::Message&)’:
[   54s] /usr/include/gtest/gtest-assertion-result.h:207:48: error: ‘make_unique’ is not a member of ‘std’
[   54s]   207 |     if (message_ == nullptr) message_ = ::std::make_unique<::std::string>();
[   54s]       |                                                ^~~~~~~~~~~
[   54s] /usr/include/gtest/gtest-assertion-result.h:207:48: note: ‘std::make_unique’ is only available from C++14 onwards
[   54s] /usr/include/gtest/gtest-assertion-result.h:207:73: error: expected primary-expression before ‘>’ token
[   54s]   207 |     if (message_ == nullptr) message_ = ::std::make_unique<::std::string>();
[   54s]       |                                                                         ^
[   54s] /usr/include/gtest/gtest-assertion-result.h:207:75: error: expected primary-expression before ‘)’ token
[   54s]   207 |     if (message_ == nullptr) message_ = ::std::make_unique<::std::string>();
[   54s]       |                                                                           ^
[   54s] In file included from /usr/include/gtest/gtest-printers.h:122,
[   54s]                  from /usr/include/gtest/gtest-matchers.h:49,
[   54s]                  from /usr/include/gtest/internal/gtest-death-test-internal.h:47,
[   54s]                  from /usr/include/gtest/gtest-death-test.h:43,
[   54s]                  from /usr/include/gtest/gtest.h:65:
[   54s] /usr/include/gtest/internal/gtest-internal.h: At global scope:
[   54s] /usr/include/gtest/internal/gtest-internal.h:622:58: error: wrong number of template arguments (0, should be 1)
[   54s]   622 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
[   54s]       |                                                          ^
[   54s] In file included from /usr/include/c++/13/string:49,
[   54s]                  from /usr/include/c++/13/bits/locale_classes.h:40,
[   54s]                  from /usr/include/c++/13/bits/ios_base.h:41,
[   54s]                  from /usr/include/c++/13/iomanip:42,
[   54s]                  from /usr/include/gtest/gtest.h:54:
[   54s] /usr/include/c++/13/bits/stl_function.h:403:12: note: provided for ‘template<class _Tp> struct std::less’
[   54s]   403 |     struct less : public binary_function<_Tp, _Tp, bool>
[   54s]       |            ^~~~
[   54s] /usr/include/gtest/internal/gtest-internal.h:622:59: error: template argument 3 is invalid
[   54s]   622 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
[   54s]       |                                                           ^~
[   54s] /usr/include/gtest/internal/gtest-internal.h: In member function ‘bool testing::internal::TypedTestSuitePState::AddTestName(const char*, int, const char*, const char*)’:

Would be grateful for any suggestion about working around this. We could patch the ade CMakeLists.txt file to change the standard to 14, of course, but do not know whether that would be advisable.

Some additional info:

  • GCC 13.2.1
  • OS: Linux (openSUSE Tumbleweed)

Thanks in advance.

@jalaei
Copy link

jalaei commented Jun 28, 2024

I have the same problem with building with gtest in Ubuntu

Thanks in advance.

@mshabunin
Copy link
Contributor

Please check whether #46 resolves your issues.

@emurray2
Copy link

Please check whether #46 resolves your issues.

This didn't work for me. I've been setting all the cmake flags I can for 4 hours and am starting to think it's an issue with gtest itself. For context, I'm trying to compile and install ROS 1 from source on Ubuntu 24.04 since I can't install it through a package manager, as it's only available for 20.04. But I'm also getting this error outside opencv and am wondering the same thing. Will keep y'all posted on what I figure out.

@mshabunin
Copy link
Contributor

Did it show this error:

[   54s]   279 | #error C++ versions less than C++14 are not supported.
[   54s]       |  ^~~~~

or something else?

For example I had issue (maybe-uninitialized error) with GTest provided by ade:

ExternalProject_Add(
GTest
URL https://github.com/google/googletest/archive/release-1.8.1.zip
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${GTEST_INSTALL_DIR} -Dgtest_force_shared_crt=ON
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)
and had to set extra CFLAGS and CXXFLAGS to avoid it (-Wno-error=maybe-uninitialized).

@emurray2
Copy link

emurray2 commented Sep 25, 2024

Did it show this error:

[   54s]   279 | #error C++ versions less than C++14 are not supported.
[   54s]       |  ^~~~~

or something else?

For example I had issue (maybe-uninitialized error) with GTest provided by ade:

ExternalProject_Add(
GTest
URL https://github.com/google/googletest/archive/release-1.8.1.zip
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${GTEST_INSTALL_DIR} -Dgtest_force_shared_crt=ON
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)

and had to set extra CFLAGS and CXXFLAGS to avoid it (-Wno-error=maybe-uninitialized).

Yup, exactly that's the error I got (the first one with the C++ 14). Not sure if it's related to this issue, but I found a hack in one of the steps I totally forgot about in this installation guide https://gist.github.com/Meltwin/fe2c15a5d7e6a8795911907f627255e0 I'm following which was to run this python script in the root of my cmake folders: https://gist.github.com/Meltwin/1ee35296d2bb86fee19d639580e3c91f.

I think it does something similar to your suggestion, but as I said it's more of a hack or brute force fix where it scans all of the folders and edits the cmake files. Not the ideal thing, but at least now my compiler isn't complaining which is good.

@emurray2
Copy link

Although I think since this is only concerning opencv, your PR should fix it as long as the edit is at the top level of the cmake lists. In my case, I had a bunch of CMake files which were somehow overriding the c++ flags even though I specified them not to be overridden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants