NVHPC 23.1 cannot handle compiling google test with c++20.
module load nvhpc/23.1 cmake/3.5 #(or higher cmake version)
git clone https://github.com/google/googletest.git
cd googletest
mkdir build && cd build
cmake -DCMAKE_CXX_FLAGS=-std=c++20 ..
make
For me, running these steps produces this error:
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
"/usr/include/c++/7/type_traits", line 1817: error: incomplete type is not allowed
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
^
detected during:
instantiation of class "std::make_unsigned<_Tp> [with _Tp=char8_t]" at line 118 of "/glade/u/home/kshores/googletest/googletest/src/gtest-printers.cc"
instantiation of "char32_t testing::<unnamed>::ToChar32(CharType) [with CharType=char8_t]" at line 237 of "/glade/u/home/kshores/googletest/googletest/src/gtest-printers.cc"
1 error detected in the compilation of "/glade/u/home/kshores/googletest/googletest/src/gtest-all.cc".
make[2]: *** [googletest/CMakeFiles/gtest.dir/build.make:76: googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 2
make[1]: *** [CMakeFiles/Makefile2:172: googletest/CMakeFiles/gtest.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
Is this an error with the configuration I chose or a compiler error?
For what it’s worth, it seems that the 23.1 compiler does not properly set the __cpluslus
macro.
With this tiny program:
#include <iostream>
int main() {
std::cout << "__cplusplus value: " << __cplusplus << std::endl;
return 0;
}
Compiled with nvc++: nvc++ --std=c++20 test.cpp
, the output I get is:
__cplusplus value: 201703
Hi kshores,
In order to be object compatible with g++, we need to use their STL. Hence when you see these types of errors, it’s often because the g++ is older and doesn’t support the language level.
Here, I can recreate your error when using a system with GNU 7.4, but it compiles correctly on a system with GNU 9.3.
Do you have access to a system with a newer g++ install?
Note that if you have newer non-default GNU install, you can have nvc++ use this install via the flag “–gcc-toolchain=/path/to/gnu/bin”.
Hope this helps,
Mat
Hi Mat,
I’m now configuring cmake like this:
cmake -DCMAKE_CXX_FLAGS=-std=c++20 --gcc-toolchain=/<longpath>/gcc/12.2.0/bin/ ..
But, this gets me a segfault error, which seems unrelated
nvc++: line 238: 149142 Segmentation fault (core dumped) $myname ${margs[MFLAGS]} "${userargs[@]}" ${margs[INC]} ${margs[LIBS]} ${margs[LDFLAGS]}
make[2]: *** [googletest/CMakeFiles/gtest.dir/build.make:76: googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 139
Hmm, I’m not sure since I can’t reproduce the error. Can you run with “make VERBOSE=1” and post the full compilation command that triggers the segv?
Here’s my output when running on system with GNU 7.4 but using a co-installed GNU 12.2.
% cmake -DCMAKE_CXX_FLAGS="-std=c++20 --gcc-toolchain=/home/sw/thirdparty/gcc/gcc-12.2.0/Linux_x86_64/bin/" ..
-- The C compiler identification is NVHPC 23.1.0
-- The CXX compiler identification is NVHPC 23.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /proj/nv/Linux_x86_64/23.1/compilers/bin/nvc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /proj/nv/Linux_x86_64/23.1/compilers/bin/nvc++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.0") found components: Interpreter
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (5.1s)
-- Generating done (0.2s)
-- Build files have been written to: /scratch/mcolgrove/tmp/googletest/build2
% make
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 25%] Linking CXX static library ../lib/libgtest.a
[ 25%] Built target gtest
[ 37%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 50%] Linking CXX static library ../lib/libgmock.a
[ 50%] Built target gmock
[ 62%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 75%] Linking CXX static library ../lib/libgmock_main.a
[ 75%] Built target gmock_main
[ 87%] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library ../lib/libgtest_main.a
[100%] Built target gtest_main
Hi Mat,
I can’t get past configuring cmake:
kshores@gust02:~/googletest/build> cmake -DCMAKE_CXX_FLAGS="-std=c++20 --gcc-toolchain=/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin/gcc" ..
-- The CXX compiler identification is NVHPC 23.1.0
-- Cray Programming Environment 2.7.20 C
-- Cray Programming Environment 2.7.20 CXX
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++
-- Check for working CXX compiler: /glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++ - broken
CMake Error at /glade/u/apps/gust/23.04/spack/opt/spack/cmake/3.25.2/gcc/7.5.0/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake:63 (message):
The C++ compiler
"/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /glade/u/home/kshores/googletest/build/CMakeFiles/CMakeScratch/TryCompile-yHoxfU
Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_18365/fast && /usr/bin/gmake -f CMakeFiles/cmTC_18365.dir/build.make CMakeFiles/cmTC_18365.dir/build
gmake[1]: Entering directory '/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeScratch/TryCompile-yHoxfU'
Building CXX object CMakeFiles/cmTC_18365.dir/testCXXCompiler.cxx.o
/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++ -std=c++20 --gcc-toolchain=/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin/gcc -MD -MT CMakeFiles/cmTC_18365.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_18365.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_18365.dir/testCXXCompiler.cxx.o -c /glade/u/home/kshores/googletest/build/CMakeFiles/CMakeScratch/TryCompile-yHoxfU/testCXXCompiler.cxx
/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++: line 238: 175016 Segmentation fault (core dumped) $myname ${margs[MFLAGS]} "${userargs[@]}" ${margs[INC]} ${margs[LIBS]} ${margs[LDFLAGS]}
gmake[1]: *** [CMakeFiles/cmTC_18365.dir/build.make:79: CMakeFiles/cmTC_18365.dir/testCXXCompiler.cxx.o] Error 139
gmake[1]: Leaving directory '/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeScratch/TryCompile-yHoxfU'
gmake: *** [Makefile:127: cmTC_18365/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:18 (project)
-- Configuring incomplete, errors occurred!
See also "/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeOutput.log".
See also "/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeError.log".
If you cannot replicate this error, then I assume it’s something to do with the machine I’m building on.
No, I’m not able to recreate this and it’s likely due to differences in our setup.
I added the Cmake flag “–debug-trycompile” so the intermediary compile tests are kept, but I’m not seeing any “.cxx” files being created. Might be differences in our CMakes.
Can you try adding “–debug-trycompile” and see if you can post the “testCXXCompiler.cxx” file that’s causing the issue? I might be able to debug it from there.
Also, try setting the environment stack limit to unlimted. While I doubt this is a stack overflow, it’s easy to check.
Here’s the test file contents, not much there:
#ifndef __cplusplus
# error "The CMAKE_CXX_COMPILER is set to a C compiler"
#endif
int main(){return 0;}
When I compile that myself, it’s able to finish properly if I don’t include the toolchain.
This is successful:
nvc++ -std=c++20 /glade/u/home/kshores/micm/build/CMakeFiles/CMakeScratch/TryCompile-oqNVpS/testCXXCompiler.cxx
This is unsuccessful:
nvc++ -std=c++20 --gcc-toolchain=/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin /glade/u/home/kshores/micm/build/CMakeFiles/CMakeScratch/TryCompile-oqNVpS/testCXXCompiler.cxx
/glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/nvhpc/23.1/bin/nvc++: line 238: 109972 Segmentation fault (core dumped) $myname ${margs[MFLAGS]} "${userargs[@]}" ${margs[INC]} ${margs[LIBS]} ${margs[LDFLAGS]}
Very odd. Something’s wrong when it’s trying to generate the configuration info. No idea what’s causing it. I’ll keep digging.
Though for your immediate issue, lets fall back to using the older method to reconfigure which GNU STL nvc++ will use.
Run the following command:
makelocalrc -d . -x -gcc /glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin/gcc -gpp /glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin/g++ -g77 /glade/u/apps/gust/23.04/spack/opt/spack/ncarcompilers/0.8.0/gcc/12.2.0/bin gfortran
This will create a “localrc” file which you can rename to whatever you prefer and copy to any directory. To use this configuration, set the environment variable “NVLOCALRC=</path/to/the/localrc>” using the path where you copied it and what ever you named the file.
@MatColgrove success! The localrc works. For now, this is a useable solution for me.
@MatColgrove I lied. After creating the localrc file and configuring googletest with cmake -DCMAKE_CXX_FLAGS=-std=c++20 ..
I get the same type trait error. I will keep trying different avenues to see if I can resolve this.