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

[Bug]: can't compile gtest-matchers.cc on Linux with gcc via bazel 5 or bazel 6 #4098

Closed
dneto0 opened this issue Dec 21, 2022 · 2 comments
Closed

Comments

@dneto0
Copy link
Contributor

dneto0 commented Dec 21, 2022

Describe the issue

On Linux x86-64 where /usr/bin/gcc is GCC 12.2.0
Building with bazel fails because the C++ compiler is compiling for C++03

INFO: Found 7 targets...
ERROR: /project/googletest/BUILD.bazel:80:11: Compiling googletest/src/gtest-matchers.cc failed: (Exit 1): gcc failed: error executing command (from target //:gtest) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 34 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from googletest/include/gtest/gtest-printers.h:114,
from googletest/include/gtest/gtest-matchers.h:48,
from googletest/src/gtest-matchers.cc:35:
googletest/include/gtest/internal/gtest-internal.h:635:58: error: wrong number of template arguments (0, should be 1)
635 | typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
| ^
In file included from /usr/include/c++/12/bits/unique_ptr.h:37,
from /usr/include/c++/12/memory:76,
from googletest/include/gtest/gtest-matchers.h:43:
/usr/include/c++/12/bits/stl_function.h:403:12: note: provided for 'template struct std::less'
403 | struct less : public binary_function<Tp, Tp, bool>
| ^~~~
googletest/include/gtest/internal/gtest-internal.h:635:59: error: template argument 3 is invalid
635 | typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
| ^~
googletest/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::AddTestName(const char*, int, const char*, const char*)':
googletest/include/gtest/internal/gtest-internal.h:612:23: error: request for member 'insert' in '((testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests
', which is of non-class type 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'int'}
612 | registered_tests
.insert(
| ^~~~~~
googletest/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::TestExists(const std::string&) const':
googletest/include/gtest/internal/gtest-internal.h:618:30: error: request for member 'count' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'const int'}
618 | return registered_tests_.count(test_name) > 0;
| ^~~~~
googletest/include/gtest/internal/gtest-internal.h: In member function 'const testing::internal::CodeLocation& testing::internal::TypedTestSuitePState::GetCodeLocation(const std::string&) const':
googletest/include/gtest/internal/gtest-internal.h:622:40: error: qualified-id in declaration before 'it'
622 | RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
| ^~
In file included from googletest/include/gtest/internal/gtest-internal.h:42:
googletest/include/gtest/internal/gtest-internal.h:623:5: error: 'it' was not declared in this scope; did you mean 'int'?
623 | GTEST_CHECK_(it != registered_tests_.end());
| ^~~~~~~~~~~~
googletest/include/gtest/internal/gtest-internal.h:623:5: error: request for member 'end' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'const int'}
623 | GTEST_CHECK_(it != registered_tests_.end());
| ^~~~~~~~~~~~
googletest/include/gtest/internal/gtest-internal.h:624:12: error: 'it' was not declared in this scope; did you mean 'int'?
624 | return it->second;
| ^~
| int
INFO: Elapsed time: 4.982s, Critical Path: 0.81s
INFO: 24 processes: 24 internal.
FAILED: Build did NOT complete successfully

Steps to reproduce the problem

git clone https://github.com/google/googletest
cd googletest
bazel build :all

What version of GoogleTest are you using?

top of tree today:
5ab508a

What operating system and version are you using?

Linux x86-64
(Google-internal distribution)

What compiler and version are you using?

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-3' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-GMvk1E/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-GMvk1E/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-3)

What build system are you using?

$ bazel --version
bazel 6.0.0

Also fails with bazel-5.0.0

Additional context

No response

@dneto0
Copy link
Contributor Author

dneto0 commented Dec 21, 2022

The critical thing is the argument given to gcc: '-std=c++0x'

dneto0 added a commit to dneto0/googletest that referenced this issue Dec 21, 2022
Googletest requires a C++14 compiler.
But Bazel can default to givin GCC option -std=c++0x which is unable
to compile googletest.

Specify -std=c++14 for any compiler that isn't MSVC and isn't on QNX.
I don't know what C++ compiler Bazel invokes for QNX.

Fixes: google#4098
dneto0 added a commit to dneto0/googletest that referenced this issue Dec 21, 2022
Use a more recent commit of googletest that uses OS constraints
from @platforms//os:* instead of from @build_tools//platforms:*

See bazelbuild/bazel#8622

Necessary to fix google#4096

Also need the fix for google#4098
copybara-service bot pushed a commit that referenced this issue Dec 22, 2022
@platforms//os:* instead of from @build_tools//platforms:*

See bazelbuild/bazel#8622

Necessary to fix #4096

Also need the fix for #4098

PiperOrigin-RevId: 497182073
Change-Id: Ifd568b088d2f779755dd20264edfd5dad12ca9cc
@dneto0
Copy link
Contributor Author

dneto0 commented Dec 22, 2022

You have to specify C++14 on the Bazel command line.

See https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#how-to-i-set-the-c-dialect-used-to-build-abseil

@dneto0 dneto0 closed this as completed Dec 22, 2022
gaspardpetit pushed a commit to eidosmontreal/googletest that referenced this issue Feb 24, 2023
@platforms//os:* instead of from @build_tools//platforms:*

See bazelbuild/bazel#8622

Necessary to fix google#4096

Also need the fix for google#4098

PiperOrigin-RevId: 497182073
Change-Id: Ifd568b088d2f779755dd20264edfd5dad12ca9cc
kunitoki pushed a commit to kunitoki/googletest that referenced this issue Nov 4, 2023
@platforms//os:* instead of from @build_tools//platforms:*

See bazelbuild/bazel#8622

Necessary to fix google#4096

Also need the fix for google#4098

PiperOrigin-RevId: 497182073
Change-Id: Ifd568b088d2f779755dd20264edfd5dad12ca9cc
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.

2 participants
@dneto0 and others