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

[c++] googletest tests fail on newer versions of googletest which dropped C++11 support #5976

Closed
yurivict opened this issue Jul 14, 2023 · 6 comments · Fixed by #5981
Closed
Labels

Comments

@yurivict
Copy link

yurivict commented Jul 14, 2023

Description

Failure message:

In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:64:
In file included from /usr/local/include/gtest/gtest-assertion-result.h:46:
In file included from /usr/local/include/gtest/gtest-message.h:57:
/usr/local/include/gtest/internal/gtest-port.h:270:2: error: C++ versions less than C++14 are not supported.
#error C++ versions less than C++14 are not supported.
 ^
In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:65:
In file included from /usr/local/include/gtest/gtest-death-test.h:43:
In file included from /usr/local/include/gtest/internal/gtest-death-test-internal.h:47:
In file included from /usr/local/include/gtest/gtest-matchers.h:48:
In file included from /usr/local/include/gtest/gtest-printers.h:115:
/usr/local/include/gtest/internal/gtest-internal.h:636:54: error: too few template arguments for class template 'less'
  typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
                                                     ^
/usr/include/c++/v1/__functional/operations.h:366:29: note: template is declared here
struct _LIBCPP_TEMPLATE_VIS less
                            ^
In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:65:
In file included from /usr/local/include/gtest/gtest-death-test.h:43:
In file included from /usr/local/include/gtest/internal/gtest-death-test-internal.h:47:
In file included from /usr/local/include/gtest/gtest-matchers.h:48:
In file included from /usr/local/include/gtest/gtest-printers.h:115:
/usr/local/include/gtest/internal/gtest-internal.h:613:22: error: member reference base type 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'int') is not a structure or union
    registered_tests_.insert(
    ~~~~~~~~~~~~~~~~~^~~~~~~
/usr/local/include/gtest/internal/gtest-internal.h:619:29: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    return registered_tests_.count(test_name) > 0;
           ~~~~~~~~~~~~~~~~~^~~~~~
/usr/local/include/gtest/internal/gtest-internal.h:623:5: error: 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'int') is not a class, namespace, or enumeration
    RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
    ^
/usr/local/include/gtest/internal/gtest-internal.h:623:62: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
                                            ~~~~~~~~~~~~~~~~~^~~~~
/usr/local/include/gtest/internal/gtest-internal.h:624:41: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    GTEST_CHECK_(it != registered_tests_.end());
                       ~~~~~~~~~~~~~~~~~^~~~
/usr/local/include/gtest/internal/gtest-port.h:1027:35: note: expanded from macro 'GTEST_CHECK_'
  if (::testing::internal::IsTrue(condition)) \
                                  ^~~~~~~~~
7 errors generated.

Environment info

LightGBM version or commit hash: 4.0.0
clang-15
pytest-7.3.1
FreeBSD 13.2

@jameslamb
Copy link
Collaborator

Thanks for using LightGBM.

Please provide the exact commands you ran which produced this error message. With just an error message, it's difficult for us to help you.

@yurivict
Copy link
Author

Complete log is here.

@jameslamb
Copy link
Collaborator

Can you explain the context of what this build is? It looks quite complicated.

For example, what are these patches?

===>  Patching for lightgbm-4.0.0
===>  Applying FreeBSD patches for lightgbm-4.0.0 from /usr/ports/misc/lightgbm/files

We'd very much appreciate if you could reduce this report to a minimal one that reproduces the problem you're facing.

@yurivict
Copy link
Author

This is a FreeBSD port build.
The patch applied is:

--- CMakeLists.txt.orig 2022-12-29 04:59:34 UTC
+++ CMakeLists.txt
@@ -507,7 +507,7 @@ endif(__BUILD_FOR_R)
 
 #-- Google C++ tests
 if(BUILD_CPP_TEST)
-  find_package(GTest CONFIG)
+  find_package(GTest)
   if(NOT GTEST_FOUND)
     message(STATUS "Did not find Google Test in the system root. Fetching Google Test now...")
     include(FetchContent)

It shouldn't matter for this issue.

The core problem is that googletest no longer supports c++11, and the project uses c++11. You should change that to c++20, for example.

@jameslamb
Copy link
Collaborator

Interesting! I guess we haven't experienced that in this project's CI because we don't preinstall googletest, and instead rely on CMake to pull in a specific, fairly-old version.

LightGBM/CMakeLists.txt

Lines 607 to 617 in d73c6b5

if(NOT GTEST_FOUND)
message(STATUS "Did not find Google Test in the system root. Fetching Google Test now...")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
FetchContent_MakeAvailable(googletest)
add_library(GTest::GTest ALIAS gtest)
endif()

That version of googletest still supported C++11. That support was dropped in v1.12.1 (June 30, 2022.

You should change that to c++20, for example.

I absolutely don't support dropping C++11, C++14, and C++17 support yet in LightGBM. That would impact a lot of the project's users, and so far we haven't found that maintaining such compatibility has been a major issue. There is some discussion in #5691 if you're curious.

However... I'd definitely support upgrading to the latest release of googletest and using the C++20 standard when running those tests. That'd give us some minimal test coverage on C++20 (we currently have none) and make it easier for repackagers like you.

I'll put up a PR for that shortly, thanks for the report and sorry for the inconvenience.

@jameslamb jameslamb changed the title Tests fail to compile: /usr/local/include/gtest/internal/gtest-port.h:270:2: error: C++ versions less than C++14 are not supported, etc [c++] googletest tests fail on newer versions of googletest which dropped C++11 support Jul 14, 2023
Copy link

github-actions bot commented Jan 1, 2025

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants