A couple of alternates (if mixing compiler versions can't be avoided): - don't need to use petsc from fortran: [balay@frog petsc]$ ./configure --with-cc=clang --with-cxx=clang++ --with-fc=0 --with-mpi=0 --download-f2cblaslapack && make && make check
- don't use c++: [balay@frog petsc]$ ./configure --with-cc=clang --with-cxx=0 --with-fc=gfortran --with-mpi=0 && make && make check - add in v14 -lstdc++ location ahead in the search path - so that even when -lgfortran is found in v11, v14 -lstdc++ gets picked up correctly. [balay@frog petsc]$ ./configure LDFLAGS=-L/opt/rh/gcc-toolset-14/root/usr/lib/gcc/x86_64-redhat-linux/14/ --with-cc=clang --with-cxx=clang++ --with-fc=gfortran --with-mpi=0 && make && make check Satish On Thu, 20 Feb 2025, Satish Balay wrote: > Ok - I see this issue on CentOS [Stream/9]. > > What I have is: > >>> > [balay@frog petsc]$ clang --version > clang version 19.1.7 (CentOS 19.1.7-1.el9) > Target: x86_64-redhat-linux-gnu > Thread model: posix > InstalledDir: /usr/bin > Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg > [balay@frog petsc]$ gfortran --version > GNU Fortran (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) > Copyright (C) 2021 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > <<<< > > Now I build: > >>> > [balay@frog petsc]$ ./configure --with-cc=clang --with-cxx=clang++ > --with-fc=gfortran --with-mpi=0 && make && make check > <snip> > ********************************************************************************* > clang -fPIC -Wall -Wwrite-strings -Wno-unknown-pragmas -Wconversion > -Wno-sign-conversion -Wno-float-conversion -Wno-implicit-float-conversion > -fstack-protector -Qunused-arguments -fvisibility=hidden -Wall > -Wwrite-strings -Wno-unknown-pragmas -Wconversion -Wno-sign-conversion > -Wno-float-conversion -Wno-implicit-float-conversion -fstack-protector > -Qunused-arguments -fvisibility=hidden -g3 -O0 -I/home/balay/petsc/include > -I/home/balay/petsc/arch-linux-c-debug/include -Wl,-export-dynamic ex19.c > -Wl,-rpath,/home/balay/petsc/arch-linux-c-debug/lib > -L/home/balay/petsc/arch-linux-c-debug/lib > -Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/11 > -L/usr/lib/gcc/x86_64-redhat-linux/11 -lpetsc -llapack -lblas -lm -lX11 > -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -o ex19 > /opt/rh/gcc-toolset-14/root//usr/lib/gcc/x86_64-redhat-linux/14/../../../../bin/ld: > /home/balay/petsc/arch-linux-c-debug/lib/libpetsc.so: undefined reference to > `std::__cxx11::basic_string<char, std::char_traits<char>, > std::allocator<char> >::_M_replace_cold(char*, unsigned long, char const*, > unsigned long, unsigned long)' > <snip> > <<<< > > Ok some v11 compiler libraries are getting mixed up (likely from -lgfortran) > causing grief. > >>>>>>>> > [root@frog ~]# yum remove gcc-toolset-14-runtime > Dependencies resolved. > ================================================================================ > Package Arch Version Repository > Size > ================================================================================ > Removing: > gcc-toolset-14-runtime x86_64 14.0-1.el9 @appstream 11 > k > Removing dependent packages: > clang x86_64 19.1.7-1.el9 @appstream 181 > k > clang-tools-extra x86_64 19.1.7-1.el9 @appstream 69 > M > gcc-toolset-14-binutils x86_64 2.41-3.el9 @appstream 27 > M > Removing unused dependencies: > clang-libs x86_64 19.1.7-1.el9 @appstream 413 > M > clang-resource-filesystem x86_64 19.1.7-1.el9 @appstream 15 > k > compiler-rt x86_64 19.1.7-1.el9 @appstream 37 > M > gcc-toolset-14-gcc x86_64 14.2.1-7.1.el9 @appstream 122 > M > gcc-toolset-14-gcc-c++ x86_64 14.2.1-7.1.el9 @appstream 39 > M > gcc-toolset-14-libstdc++-devel x86_64 14.2.1-7.1.el9 @appstream 22 > M > libomp x86_64 19.1.7-1.el9 @appstream 1.9 > M > libomp-devel x86_64 19.1.7-1.el9 @appstream 31 > M > > Transaction Summary > ================================================================================ > Remove 12 Packages > > Freed space: 763 M > Is this ok [y/N]: > <<<<< > > So this install of clang depends-on/requires gcc-toolset-14-gcc. Also > gfortran-14 is missing. Try installing it. > >>>> > [root@frog ~]# yum install gcc-toolset-14-gcc-gfortran > <<<< > > Now retry build: > >>> > [balay@frog petsc]$ ./configure --with-cc=clang --with-cxx=clang++ > --with-fc=gfortran --with-mpi=0 && make && make check > <snip> > Running PETSc check examples to verify correct installation > Using PETSC_DIR=/home/balay/petsc and PETSC_ARCH=arch-linux-c-debug > C/C++ example src/snes/tutorials/ex19 run successfully with 1 MPI process > Fortran example src/snes/tutorials/ex5f run successfully with 1 MPI process > Completed PETSc check examples > [balay@frog petsc]$ > <<<< > > Hm - Using gfortran-11 here [with gfortran-14 installed] somehow worked! But > perhaps its better to use gfortran-14 [as this install of clang requires > g++-14] > >>>> > [balay@frog petsc]$ export PATH=/opt/rh/gcc-toolset-14/root/usr/bin:$PATH > [balay@frog petsc]$ gfortran --version > GNU Fortran (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) > Copyright (C) 2024 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > [balay@frog petsc]$ ./configure --with-cc=clang --with-cxx=clang++ > --with-fc=gfortran --with-mpi=0 && make && make check > <snip> > CLINKER arch-linux-c-debug/lib/libpetsc.so.3.22.3 > ========================================= > Now to check if the libraries are working do: > make PETSC_DIR=/home/balay/petsc PETSC_ARCH=arch-linux-c-debug check > ========================================= > Running PETSc check examples to verify correct installation > Using PETSC_DIR=/home/balay/petsc and PETSC_ARCH=arch-linux-c-debug > C/C++ example src/snes/tutorials/ex19 run successfully with 1 MPI process > Fortran example src/snes/tutorials/ex5f run successfully with 1 MPI process > Completed PETSc check examples > [balay@frog petsc]$ > <<<< > > So that worked! > > Satish > > > On Thu, 20 Feb 2025, Satish Balay wrote: > > > Actually, simpler: > > > > ./configure --with-cc=clang --with-cxx=clang++ --with-fc=gfortran > > --with-mpi=0 > > --download-fblaslapack="$(DIR_SRC)/fblaslapack-$(FBLASLAPACK_VERSION).tar.gz" > > && make && make check > > > > > /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../bin/ld > > > > Hm - there was in issue with some (clang versions?) incompatibilities with > > gcc-12 - I think using gcc-11 (system default in that use case) worked. I'm > > not sure if you are seeing the same issue here. > > > > Satish > > > > On Thu, 20 Feb 2025, Satish Balay wrote: > > > > > > > > Any particular reason to use these flags? What clang version? OS? > > > > > > Best if you can send build logs [perhaps to petsc-maint] > > > > > > Can you try a simpler build and see if it works: > > > > > > ./configure --with-mpi-dir=/PATH_TO/models/src/v2021.03-2.0.3-llvm > > > --download-fblaslapack="$(DIR_SRC)/fblaslapack-$(FBLASLAPACK_VERSION).tar.gz" > > > && make && make check > > > or: > > > ./configure --with-cc=clang --with-cxx=clang++ --with-fc=gfortran > > > --download-mpich="$(DIR_SRC)/mpich-$(MPICH_VERSION).tar.gz" > > > --download-fblaslapack="$(DIR_SRC)/fblaslapack-$(FBLASLAPACK_VERSION).tar.gz" > > > && make && make check > > > > > > Satish > > > > > > On Thu, 20 Feb 2025, Michael Schaferkotter wrote: > > > > > > > build petsc-3.20.3 with llvm, clang, clang++, gfortran > > > > > > > > CFLAGS='-std=c++11' > > > > CXXFLAGS='-std=c++11 -D_GLIBCXX_USE_CXX11_ABI=1' > > > > LDLIBS += -lstdc++ > > > > > > > > $PETSC_ARCH arch-linux-c-opt > > > > MPIF90 = ./models/src/v2021.03-2.0.3-llvm/bin/mpif90 > > > > MPICC = ./models/src/v2021.03-2.0.3-llvm/bin/mpicc > > > > CLANG = clang > > > > FC = gfortran > > > > > > > > > > > > Petsc libraries are built; > > > > /models/src/v2021.03-2.0.3-llvm/lib/libpetsc.so@ > > > > /models/src/v2021.03-2.0.3-llvm/lib/libpetsc.so.3.020@ > > > > /models/src/v2021.03-2.0.3-llvm/lib/libpetsc.so.3.020.3* > > > > > > > > > > > > The configure is this: > > > > cd $(PETSC_SRC) && unset CXX CC FC F77 && $(PYTHON2) > > > > ./configure --prefix=$(PREFIX) \ > > > > --with-cc=clang \ > > > > --with-cxx=clang++ \ > > > > --with-fc=gfortran \ > > > > --download-mpich="$(DIR_SRC)/mpich-$(MPICH_VERSION).tar.gz" \ > > > > > > > > --download-fblaslapack="$(DIR_SRC)/fblaslapack-$(FBLASLAPACK_VERSION).tar.gz" > > > > \ > > > > --download-sowing \ > > > > --with-debugging=$(PETSC_DBG) \ > > > > --with-shared-libraries=1 \ > > > > CFLAGS='-std=c11' \ > > > > CXXFLAGS='-std=c++11 -D_GLIBCXX_USE_CXX11_ABI=1' \ > > > > CPPFLAGS='-D_GLIBCXX_USE_CXX11_ABI=1' \ > > > > LDFLAGS='-L$(LLVM_LIB)' \ > > > > LIBS='-lstdc++’ \ > > > > --COPTFLAGS=$(COPTFLAGS) --CXXOPTFLAGS=$(CXXOPTFLAGS) > > > > --FOPTFLAGS=$(FOPTFLAGS) > > > > > > > > > > > > Here is the make: > > > > > > > > $(MAKE) -C $(PETSC_SRC) PETSC_DIR=$(PETSC_SRC) > > > > PETSC_ARCH=$(PETSC_ARCH) all > > > > > > > > > > > > Check-petsc is: > > > > > > > > $(MAKE) -C $(PETSC_SRC) PETSC_DIR=$(PETSC_SRC) > > > > PETSC_ARCH=$(PETSC_ARCH) test > > > > > > > > Here is the log file for test: > > > > > > > > make[1]: Entering directory > > > > '/models/src/v2021.03-2.0.3-llvm/build/petsc/petsc-3.20.3' > > > > /usr/bin/python3 > > > > /models/src/v2021.03-2.0.3-llvm/build/petsc/petsc-3.20.3/config/gmakegentest.py > > > > --petsc-dir=/models/src/v2021.03-2.0.3-llvm/build/petsc/petsc-3.20.3 > > > > --petsc-arch=arch-linux-c-opt --testdir=./arch-linux-c-opt/tests > > > > --srcdir /models/src/v2021.03-2.0.3-llvm/build/petsc/petsc-3.20.3/src > > > > --pkg-pkgs "sys vec mat dm ksp snes ts tao" > > > > Using MAKEFLAGS: iw -- PETSC_ARCH=arch-linux-c-opt > > > > PETSC_DIR=/models/src/v2021.03-2.0.3-llvm/build/petsc/petsc-3.20.3 > > > > CC arch-linux-c-opt/tests/sys/classes/draw/tests/ex1.o > > > > CLINKER arch-linux-c-opt/tests/sys/classes/draw/tests/ex1 > > > > /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../bin/ld: > > > > arch-linux-c-opt/lib/libpetsc.so: undefined reference to > > > > `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, > > > > std::allocator<char> >::basic_ostringstream()' > > > > /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../bin/ld: > > > > arch-linux-c-opt/lib/libpetsc.so: undefined reference to > > > > `std::__throw_bad_array_new_length()' > > > > clang: error: linker command failed with exit code 1 (use -v to see > > > > invocation) > > > > make[1]: [gmakefile.test:273: > > > > arch-linux-c-opt/tests/sys/classes/draw/tests/ex1] Error 1 (ignored) > > > > > > > > > > > > There are many errors of the ilk: > > > > > > > > std::__cxx11::basic_ostringstream<char, std::char_traits<char>, > > > > std::allocator<char> >::basic_ostringstream() > > > > > > > > [lib]$ nm -A libpetsc.so | grep basic_ostringstream > > > > libpetsc.so: U > > > > _ZNKSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEE3strEv@GLIBCXX_3.4.21 > > > > libpetsc.so: U > > > > _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev > > > > libpetsc.so: U > > > > _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev@GLIBCXX_3.4.21 > > > > > > > > > > > > I/m new to llvm and this is the first time to compile petsc.3.20.3 with > > > > llvm compilers. > > > > > > > > Clearly something is amiss. > > > > > > > > Any ideas appreciated. > > > > > > > > Michael > > > > > > > > > > > > > > > > >