opencv / ade

Apache License 2.0
61 stars 50 forks source link

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

Open badshah400 opened 5 months ago

badshah400 commented 5 months ago

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:

Thanks in advance.

jalaei commented 3 months ago

I have the same problem with building with gtest in Ubuntu

Thanks in advance.

mshabunin commented 1 week ago

Please check whether #46 resolves your issues.

emurray2 commented 1 week ago

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 commented 1 week ago

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: https://github.com/opencv/ade/blob/0e8a2ccdd34f29dba55894f5f3c5179809888b9e/sources/tests/CMakeLists.txt#L16-L23 and had to set extra CFLAGS and CXXFLAGS to avoid it (-Wno-error=maybe-uninitialized).

emurray2 commented 1 week ago

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:

https://github.com/opencv/ade/blob/0e8a2ccdd34f29dba55894f5f3c5179809888b9e/sources/tests/CMakeLists.txt#L16-L23 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 commented 1 week ago

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.