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

Piro: Linking issue with gfortran, undefined reference to `_gfortran... #8632

Closed
tuckerhartland opened this issue Jan 25, 2021 · 15 comments
Closed

Comments

@tuckerhartland
Copy link

Question

@trilinos/<Piro>

I have been working with Trilinos for a short time. I have had success in building Trilinos with BUILD_SHARED_LIBS=OFF, but in order to build Trilinos with PyTrilinos enabled, I need to set BUILD_SHARED_LIBS=ON. Unfortunately I receive the following error when I try to do a shared library build of Trilinos.

[ 98%] Linking CXX executable Piro_TempusSolver_SensitivitySinCosUnitTests.exe
/usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_transfer_character_write' /usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_st_write_done'
/usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_concat_string' /usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_stop_string'
/usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_transfer_integer_write' /usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to _gfortran_string_len_trim'
/usr/bin/ld: ../../teuchos/numerics/src/libteuchosnumerics.so.13.1: undefined reference to `_gfortran_st_write'
collect2: error: ld returned 1 exit status
make[2]: *** [packages/piro/test/CMakeFiles/Piro_TempusSolver_SensitivitySinCosUnitTests.dir/build.make:199: packages/piro/test/Piro_TempusSolver_SensitivitySinCosUnitTests.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:17768: packages/piro/test/CMakeFiles/Piro_TempusSolver_SensitivitySinCosUnitTests.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Any suggestions to fix this build issue would be greatly appreciated. Let me know if there is more information that I could provide that would help you understand the issue that I am having.

@kliegeois
Copy link
Contributor

Could you copy/paste the configuration script that you used to configure Trilinos before the compilation?

Have you set any Fortran options during the configuration of Trilinos?
I do not know if this can help but can you try this option in your configuration script?

-D Trilinos_ENABLE_Fortran:BOOL=ON \

Have you try to fully clean the build directory and rebuild from scratch?

@rppawlo
Copy link
Contributor

rppawlo commented Jan 25, 2021

Try adding this:

-D CMAKE_EXE_LINKER_FLAGS:STRING="-lgfortran"

@tuckerhartland
Copy link
Author

Thank you both for the suggestions, I have followed up with both of these and they did not remedy the issue. I had previously not set
-D Trilinos_ENABLE_Fortran:Bool=ON
I obtained the same error as before, after running make clean, sourcing the configure file and make -jN install.

I then added -D CMAKE_EXE_LINKER_FLAGS:STRING="-lgfortran" to the configure file and then upon running this configure script I obtained the error (the configuration script follows the error message).

-- Verifying Fortran/CXX Compiler Compatibility - Failed
CMake Error at /usr/share/cmake-3.16/Modules/FortranCInterface.cmake:383 (message):
The Fortran compiler:

/usr/bin/mpif90

and the CXX compiler:

/usr/bin/mpicxx

failed to compile a simple test project using both languages. The output
was

Change Dir: /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX

Run Build Command(s):/usr/bin/make VerifyFortranC && /usr/bin/cmake -S/usr/share/cmake-3.16/Modules/FortranCInterface/Verify -B/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/make -f CMakeFiles/Makefile2 VerifyFortranC
make[1]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/bin/cmake -S/usr/share/cmake-3.16/Modules/FortranCInterface/Verify -B/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles 6
/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/VerifyFortranC.dir/all
make[2]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/bin/make -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/depend
make[3]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
cd /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /usr/share/cmake-3.16/Modules/FortranCInterface/Verify /usr/share/cmake-3.16/Modules/FortranCInterface/Verify /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortran.dir/DependInfo.cmake
Scanning dependencies of target VerifyFortran
make[3]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/bin/make -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/build
make[3]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
[ 16%] Building Fortran object CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
/usr/bin/mpif90 -DVERIFY_CXX -I/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX  -O3   -c /usr/share/cmake-3.16/Modules/FortranCInterface/Verify/VerifyFortran.f -o CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
[ 33%] Linking Fortran static library libVerifyFortran.a
/usr/bin/cmake -P CMakeFiles/VerifyFortran.dir/cmake_clean_target.cmake
/usr/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortran.dir/link.txt --verbose=1
/usr/bin/ar qc libVerifyFortran.a  CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
/usr/bin/ranlib libVerifyFortran.a
make[3]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
[ 33%] Built target VerifyFortran
/usr/bin/make -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/depend
make[3]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
cd /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /usr/share/cmake-3.16/Modules/FortranCInterface/Verify /usr/share/cmake-3.16/Modules/FortranCInterface/Verify /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX /home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortranC.dir/DependInfo.cmake
Scanning dependencies of target VerifyFortranC
make[3]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/bin/make -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/build
make[3]: Entering directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
[ 50%] Building C object CMakeFiles/VerifyFortranC.dir/main.c.o
/usr/bin/mpicc -DVERIFY_CXX -I/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX  -O3 -DNDEBUG   -o CMakeFiles/VerifyFortranC.dir/main.c.o   -c /usr/share/cmake-3.16/Modules/FortranCInterface/Verify/main.c
[ 66%] Building C object CMakeFiles/VerifyFortranC.dir/VerifyC.c.o
/usr/bin/mpicc -DVERIFY_CXX -I/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX  -O3 -DNDEBUG   -o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o   -c /usr/share/cmake-3.16/Modules/FortranCInterface/Verify/VerifyC.c
[ 83%] Building CXX object CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o
/usr/bin/mpicxx  -DVERIFY_CXX -I/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX  -g -O3 -fPIC -fno-var-tracking -O3 -DNDEBUG   -o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -c /usr/share/cmake-3.16/Modules/FortranCInterface/Verify/VerifyCXX.cxx
[100%] Linking CXX executable VerifyFortranC
/usr/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortranC.dir/link.txt --verbose=1
/usr/bin/mpicxx    -g -O3 -fPIC -fno-var-tracking -O3 -DNDEBUG   CMakeFiles/VerifyFortranC.dir/main.c.o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o  -o VerifyFortranC  libVerifyFortran.a -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lquadmath 
/usr/bin/ld: libVerifyFortran.a(VerifyFortran.f.o): in function `verifyfortran_':
VerifyFortran.f:(.text+0x31): undefined reference to `_gfortran_st_write'
/usr/bin/ld: VerifyFortran.f:(.text+0x45): undefined reference to `_gfortran_transfer_character_write'
/usr/bin/ld: VerifyFortran.f:(.text+0x4d): undefined reference to `_gfortran_st_write_done'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/VerifyFortranC.dir/build.make:118: VerifyFortranC] Error 1
make[3]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
make[2]: *** [CMakeFiles/Makefile2:81: CMakeFiles/VerifyFortranC.dir/all] Error 2
make[2]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
make[1]: *** [CMakeFiles/Makefile2:88: CMakeFiles/VerifyFortranC.dir/rule] Error 2
make[1]: Leaving directory '/home/tucker/software/Trilinos/builds/devel-shared3/CMakeFiles/FortranCInterface/VerifyCXX'
make: *** [Makefile:121: VerifyFortranC] Error 2

Call Stack (most recent call first):
cmake/tribits/core/package_arch/TribitsFortranMangling.cmake:50 (FortranCInterface_VERIFY)
cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake:2143 (INCLUDE)
cmake/tribits/core/package_arch/TribitsProjectImpl.cmake:193 (TRIBITS_SETUP_ENV)
cmake/tribits/core/package_arch/TribitsProject.cmake:93 (TRIBITS_PROJECT_IMPL)
CMakeLists.txt:90 (TRIBITS_PROJECT)


The following is my configuration script

!/bin/sh

rm -fr CMake*

TRILINSTALLDIR=$HOME/software/Trilinos/builds/devel-shared3/install
TRILINOSHOME=$HOME/software/Trilinos
HDF5DIR="$HOME/software/hdf5/MY_BUILD"
NETCDFDIR="$HOME/software/netcdf-c-4.7.4/MY_BUILD"
PNETCDFDIR="$HOME/software/parallel-netcdf-1.6.1/MY_BUILD"
SUPERLUDIR="$HOME/software/superlu"
PARMETISDIR=/usr/local
METISDIR=/usr/local

BLASDIR=/usr/local
LAPACKDIR=/usr/local

cmake
-D BUILD_SHARED_LIBS:BOOL=ON
-D HAVE_dggsvd3_POST=0
-D Trilinos_ENABLE_Fortran:BOOL=ON
-D CMAKE_EXE_LINKER_FLAGS:STRING="-lgfortran"
-D CMAKE_INSTALL_PREFIX:PATH=$TRILINSTALLDIR
-D CMAKE_BUILD_TYPE:STRING=RELEASE
-D Tpetra_ENABLE_Kokkos_Refactor:BOOL=ON
-D KOKKOS_ENABLE_DEPRECATED_CODE=OFF
-D Tpetra_ENABLE_DEPRECATED_CODE=OFF
-D Belos_HIDE_DEPRECATED_CODE=ON
-D Epetra_HIDE_DEPRECATED_CODE=ON
-D Ifpack2_HIDE_DEPRECATED_CODE=ON
-D Ifpack2_ENABLE_DEPRECATED_CODE=OFF
-D MueLu_ENABLE_DEPRECATED_CODE=OFF
-D Panzer_HIDE_DEPRECATED_CODE=ON
-D Phalanx_HIDE_DEPRECATED_CODE=ON
-D STK_HIDE_DEPRECATED_CODE=ON
-D Teuchos_HIDE_DEPRECATED_CODE=OFF
-D Thyra_HIDE_DEPRECATED_CODE=ON
-D Xpetra_ENABLE_DEPRECATED_CODE:BOOL=OFF
-D Trilinos_WARNINGS_AS_ERRORS_FLAGS:STRING=""
-D Trilinos_ENABLE_ALL_PACKAGES:BOOL=OFF
-D Trilinos_ENABLE_ALL_OPTIONAL_PACKAGES:BOOL=OFF
-D Trilinos_ENABLE_Teuchos:BOOL=ON
-D Trilinos_ENABLE_Shards:BOOL=ON
-D Trilinos_ENABLE_Sacado:BOOL=ON
-D Trilinos_ENABLE_SEACAS:BOOL=ON
-D Trilinos_ENABLE_Epetra:BOOL=ON
-D Trilinos_ENABLE_EpetraExt:BOOL=ON
-D Trilinos_ENABLE_Ifpack:BOOL=ON
-D Trilinos_ENABLE_AztecOO:BOOL=ON
-D Trilinos_ENABLE_Amesos:BOOL=ON
-D Trilinos_ENABLE_Anasazi:BOOL=ON
-D Anasazi_ENABLE_RBGen:BOOL=ON
-D Trilinos_ENABLE_Belos:BOOL=ON
-D Trilinos_ENABLE_ML:BOOL=ON
-D Trilinos_ENABLE_Phalanx:BOOL=ON
-D Trilinos_ENABLE_Intrepid2:BOOL=ON
-D Trilinos_ENABLE_NOX:BOOL=ON
-D Trilinos_ENABLE_Stratimikos:BOOL=ON
-D Trilinos_ENABLE_Thyra:BOOL=ON
-D Trilinos_ENABLE_Stokhos:BOOL=OFF
-D Trilinos_ENABLE_Isorropia:BOOL=ON
-D Trilinos_ENABLE_Piro:BOOL=ON
-D Trilinos_ENABLE_STK:BOOL=ON
-D Trilinos_ENABLE_STKSearchUtil:BOOL=OFF
-D Trilinos_ENABLE_STKUnit_tests:BOOL=OFF
-D Trilinos_ENABLE_STKDoc_tests:BOOL=OFF
-D Trilinos_ENABLE_SEACASIoss:BOOL=ON
-D Trilinos_ENABLE_SEACASExodus:BOOL=ON
-D TPL_ENABLE_Matio:BOOL=OFF
-D Trilinos_ENABLE_Teko:BOOL=ON
-D Trilinos_ENABLE_Zoltan:BOOL=ON
-D Zoltan_ENABLE_ULONG_IDS:BOOL=ON
-D Trilinos_ENABLE_FEI:BOOL=OFF
-D Trilinos_ENABLE_TESTS:BOOL=OFF
-D Piro_ENABLE_TESTS:BOOL=ON
-D Epetra_ENABLE_TESTS:BOOL=OFF
-D Xpetra_ENABLE_Epetra:BOOL=OFF
-D MueLu_ENABLE_Epetra:BOOL=OFF
-D Trilinos_ENABLE_EXPLICIT_INSTANTIATION:BOOL=ON
-D Trilinos_ENABLE_ROL:BOOL=ON
-D Trilinos_ENABLE_Tempus:BOOL=ON
-D Trilinos_ENABLE_ShyLU_DDFROSch:BOOL=ON
-D ROL_ENABLE_TESTS:BOOL=OFF
-D ROL_ENABLE_DEBUG:BOOL=ON
-D ROL_ENABLE_EXAMPLES:BOOL=OFF
-D ML_ENABLE_TESTS:BOOL=OFF
-D Phalanx_ENABLE_TESTS:BOOL=OFF
-D Trilinos_ENABLE_PanzerExprEval:BOOL=ON
-D Trilinos_ENABLE_PanzerDofMgr:BOOL=ON
-D Trilinos_ENABLE_EXAMPLES:BOOL=OFF
-D TPL_ENABLE_MPI:BOOL=ON
-D TPL_ENABLE_Boost:BOOL=ON
-D TPL_ENABLE_HDF5:BOOL=ON
-D TPL_ENABLE_Netcdf:BOOL=ON
-D TPL_Netcdf_PARALLEL:BOOL=ON

-D Trilinos_ENABLE_Tpetra:BOOL=ON
-D Trilinos_ENABLE_Kokkos:BOOL=ON
-D Trilinos_ENABLE_KokkosCore:BOOL=ON
-D Phalanx_KOKKOS_DEVICE_TYPE:STRING="SERIAL"
-D Phalanx_INDEX_SIZE_TYPE:STRING="INT"
-D Phalanx_SHOW_DEPRECATED_WARNINGS:BOOL=OFF
-D Kokkos_ENABLE_SERIAL:BOOL=ON
-D Kokkos_ENABLE_OPENMP:BOOL=OFF
-D Kokkos_ENABLE_PTHREAD:BOOL=OFF
-D Trilinos_ENABLE_Ifpack2:BOOL=ON
-D Trilinos_ENABLE_Amesos2:BOOL=ON
-D Trilinos_ENABLE_Zoltan2:BOOL=ON
-D Zoltan2_ENABLE_ParMETIS:BOOL=ON

-D Trilinos_ENABLE_MueLu:BOOL=ON
-D TPL_ENABLE_SuperLU:STRING=OFF
-D SuperLU_INCLUDE_DIRS:STRING="${SUPERLUDIR}/include"
-D SuperLU_LIBRARY_DIRS:STRING="${SUPERLUDIR}/lib"
-D TPL_SuperLU_LIBRARIES:FILEPATH="${SUPERLUDIR}/lib/libsuperlu.a"
-D Phalanx_ENABLE_TEUCHOS_TIME_MONITOR:BOOL=ON
-D Phalanx_ALLOW_MULTIPLE_EVALUATORS_FOR_SAME_FIELD:BOOL=OFF
-D Stratimikos_ENABLE_TEUCHOS_TIME_MONITOR:BOOL=ON

-D CMAKE_VERBOSE_MAKEFILE:BOOL=OFF
-D Trilinos_VERBOSE_CONFIGURE:BOOL=OFF
-D CMAKE_CXX_FLAGS:STRING="-g -O3 -fPIC -fno-var-tracking"

-D Boost_INCLUDE_DIRS:PATH="/usr/include/boost"
-D Boost_LIBRARY_DIRS:PATH="/usr/lib/boost"
-D HDF5_INCLUDE_DIRS:PATH="${HDF5DIR}/include"
-D HDF5_LIBRARY_DIRS:PATH="${HDF5DIR}/lib"
-D Netcdf_INCLUDE_DIRS:PATH="${NETCDFDIR}/include; ${PNETCDFDIR}/include"
-D Netcdf_LIBRARY_DIRS:PATH="${NETCDFDIR}/lib; ${PNETCDFDIR}/lib"
-D Trilinos_ENABLE_Pamgen:BOOL=ON

-D Trilinos_ENABLE_EXPORT_MAKEFILES:BOOL=OFF
-D Trilinos_ASSERT_MISSING_PACKAGES:BOOL=OFF
-D TPL_ENABLE_ParMETIS:STRING=ON
-D TPL_ParMETIS_INCLUDE_DIRS:PATH="${PARMETISDIR}/include"
-D TPL_ParMETIS_LIBRARIES:PATH="${PARMETISDIR}/lib/libparmetis.a;${METISDIR}/lib/libmetis.a"
-D TPL_ENABLE_METIS:STRING=ON
-D TPL_METIS_INCLUDE_DIRS:PATH="${METISDIR}/include"
-D TPL_METIS_LIBRARIES:FILEPATH="${METISDIR}/lib/libmetis.a"
-D TPL_ENABLE_BLAS:BOOL=ON
-D TPL_BLAS_LIBRARIES:FILEPATH="${BLASDIR}/lib/libblas.a"
-D Trilinos_ENABLE_TriKota:BOOL=OFF
-D TPL_ENABLE_LAPACK:BOOL=ON
-D TPL_LAPACK_LIBRARIES:FILEPATH="${LAPACKDIR}/lib/liblapack.a;"
\

@jhux2
Copy link
Member

jhux2 commented Jan 28, 2021

@tuckerhartland You might try adding the option --debug-trycompile to your cmake line. This will I believe keep the test program that cmake is trying to compile with mpif90/mpicxx plus an error file. Inspecting both of those might give a hint of what exactly is wrong with the compile line.

@rppawlo
Copy link
Contributor

rppawlo commented Jan 28, 2021

I've seen this issue before. The linker needs -lgfortran. By adding -D CMAKE_EXE_LINKER_FLAGS:STRING="-lgfortran" Trilinos tests will correctly link, however the internal cmake check of the fortran compiler seems to ignore the CMAKE_EXE_LINKER_FLAGS. @bradking - is it possible to manually add link flags to the compiler internal checks? I was able to work around this on one machine by disabling fortran support (you can still link Trilinos against fortran libraries like blas).

@bradking
Copy link
Contributor

@rppawlo make sure policy CMP0056 is set to NEW before CMake enables the Fortran language. The simplest way to do that is to use cmake_minimum_required(VERSION 3.2) or higher before any project() or enable_langauge() call.

@rppawlo
Copy link
Contributor

rppawlo commented Feb 1, 2021

Thanks @bradking !

@tuckerhartland - can you try adding CMAKE_POLICY_DEFAULT_CMP0056=NEW to your configure? Based on this comment from cmake documentation, you are probably getting the old behavior:

This policy was introduced in CMake version 3.2. Unlike most policies, CMake version 3.19.4 does not warn by default when this policy is not set and simply uses OLD behavior. See documentation of the CMAKE_POLICY_WARNING_CMP0056 variable to control the warning.

@tuckerhartland
Copy link
Author

@bradking @rppawlo thank you for the suggestions.

Adding CMAKE_POLICY_DEFAULT_CMP0056=NEW to the configure script did not remedy the issue. I still have the same issues as before, that is

  • with the config option -D CMAKE_EXE_LINKER_FLAGS:STRING="-lgfortran", I receive the following error message upon running the configure script.
    [100%] Linking CXX executable VerifyFortranC
    /usr/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortranC.dir/link.txt --verbose=1
    /usr/bin/mpicxx -g -O3 -fPIC -fno-var-tracking -O3 -DNDEBUG CMakeFiles/VerifyFortranC.dir/main.c.o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -o VerifyFortranC libVerifyFortran.a -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lquadmath
    /usr/bin/ld: libVerifyFortran.a(VerifyFortran.f.o): in function verifyfortran_': VerifyFortran.f:(.text+0x31): undefined reference to _gfortran_st_write'
    /usr/bin/ld: VerifyFortran.f:(.text+0x45): undefined reference to _gfortran_transfer_character_write' /usr/bin/ld: VerifyFortran.f:(.text+0x4d): undefined reference to _gfortran_st_write_done'
    collect2: error: ld returned 1 exit status
    make[3]: *** [CMakeFiles/VerifyFortranC.dir/build.make:118: VerifyFortranC] Error 1
    make[3]: Leaving directory '/home/tucker/software/Trilinos/builds/github-issue-test-devel-shared/CMakeFiles/FortranCInterface/VerifyCXX'
    make[2]: *** [CMakeFiles/Makefile2:81: CMakeFiles/VerifyFortranC.dir/all] Error 2
    make[2]: Leaving directory '/home/tucker/software/Trilinos/builds/github-issue-test-devel-shared/CMakeFiles/FortranCInterface/VerifyCXX'
    make[1]: *** [CMakeFiles/Makefile2:88: CMakeFiles/VerifyFortranC.dir/rule] Error 2
    make[1]: Leaving directory '/home/tucker/software/Trilinos/builds/github-issue-test-devel-shared/CMakeFiles/FortranCInterface/VerifyCXX'
    make: *** [Makefile:121: VerifyFortranC] Error 2

  • without the additional option CMAKE_EXE_LINKER_FLAGS option, running the configure is successful but fails upon building as before, with references to undefined references to symbols that should be found in the fortran libraries that I am trying to link to.

@bradking
Copy link
Contributor

bradking commented Feb 2, 2021

The VerifyFortranC failure is probably due to CMake Issue 21408, which is about CMP0056 not being honored by FortranCInterface. That's been fixed by CMake MR 5483, and the fix will be in CMake 3.20. One could build CMake from source or try a nightly binary to get that fix.

However, it should not be necessary to add -lgfortran by hand in the first place. CMake is supposed to detect the libraries implicitly linked by each language's compiler and then add them automatically when linking mixed-language binaries. Please go to the top of the build tree and run

$  grep _IMPLICIT_LINK_ CMakeFiles/*/CMake*Compiler.cmake

What is its output?

@tuckerhartland
Copy link
Author

Thanks again @bradking for further insight into the source of the error. I am not certain why this issue wouldn't be more prevalent if it is due to the CMake Issue that you suggested.

CMakeFiles/3.16.3/CMakeCCompiler.cmake:set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "mpi;gcc;gcc_s;pthread;c;gcc;gcc_s")
CMakeFiles/3.16.3/CMakeCCompiler.cmake:set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/x86_64-linux-gnu/openmpi/lib;/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
CMakeFiles/3.16.3/CMakeCCompiler.cmake:set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
CMakeFiles/3.16.3/CMakeCXXCompiler.cmake:set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "mpi_cxx;mpi;stdc++;m;gcc_s;gcc;pthread;c;gcc_s;gcc")
CMakeFiles/3.16.3/CMakeCXXCompiler.cmake:set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/x86_64-linux-gnu/openmpi/lib;/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
CMakeFiles/3.16.3/CMakeCXXCompiler.cmake:set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
CMakeFiles/3.16.3/CMakeFortranCompiler.cmake:set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "mpi_usempif08;mpi_usempi_ignore_tkr;mpi_mpifh;mpi;gfortran;m;gcc_s;gcc;quadmath;m;gcc_s;gcc;pthread;c;gcc_s;gcc")
CMakeFiles/3.16.3/CMakeFortranCompiler.cmake:set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "/usr/lib/x86_64-linux-gnu/openmpi/lib;/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
CMakeFiles/3.16.3/CMakeFortranCompiler.cmake:set(CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")

I then built a more recent version of CMake (version 3.19.4) and tried configuring and building but had this did not remedy the previously stated issues.

@bradking
Copy link
Contributor

bradking commented Feb 3, 2021

Thanks. The CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES list does contain gfortran. That should cause CMake to add that library explicitly when using the C++ compiler to link a project that uses Fortran and C++ together. In your VerifyFortranC output a few posts back, one can see the link line:

/usr/bin/mpicxx ... -o VerifyFortranC libVerifyFortran.a -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lquadmath

That does list several of the libraries from CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES, so it is mysterious that -lgfortran is not included too.

I just ran one of CMake's tests for FortranCInterface using mpicc/mpicxx/mpif90 as the compilers, and I can see that the VerifyFortranC binary is linked with an explicit -lgfortran flag added by CMake.

@tuckerhartland let's try a simpler case on your machine. Create a CMakeLists.txt file in a fresh source tree (e.g. src):

cmake_minimum_required(VERSION 3.16)
project(Example LANGUAGES C CXX Fortran)
include(FortranCInterface)
FortranCInterface_VERIFY()
FortranCInterface_VERIFY(CXX)

Then create a fresh build tree and run env CC=mpicc CXX=mpicxx FC=mpif90 cmake ../src. Does the detection and verification work in the simple case?

@tuckerhartland
Copy link
Author

Hello @bradking, thank you again for a helpful suggestion.

Detection and verification was successful for this simple build example as I obtained the following upon running cmake on the CMakeLists.txt file. I also see that libgfortran.so is linked to the FortranCInterface binary via the command ldd CMakeFiles/FortranCInterface/FortranCInterface. To me it then appears that the issue with the Trilinos build is not necessarily due to a bug with my CMake, Fortran compilers and C compiler installs.

@rppawlo
Copy link
Contributor

rppawlo commented Feb 12, 2021

@bartlettroscoe - given the evidence above, I think the next question is: does tribits somehow overwrite the fortran link flags?

@bartlettroscoe
Copy link
Member

bartlettroscoe commented Feb 12, 2021

CC: @rppawlo

@tuckerhartland, dealing with issues like this have been such a pain over the years. It has been a long time since I have seen a link error like this but the way we resolved this was to tack on -lgfortran to the list of link libraries for BLAS (which is usually what needs this library). So on many systems we have used something like:

-D TPL_BLAS_LIBRARIES="-L/usr/lib64/;-lblas;-lgfortran;-lgomp;-lm"

See if that works.

A lot has changed in CMake in the last 10 years since we get everything working so we may revisit issues like this as part of TriBITSPub/TriBITS#299.

It would be so nice if we could find a way to make CMake automatically tack on libraries like -lgfortran and the end of the link lines but I guess that assumes that CMake knows that a C++ program needs to link in -lgfotran (due to an indirect TPL that needs it). This was so hard to do 10 years ago so we put in workarounds. (And those workarounds may be getting in the way of how modern CMake expects things wo work with link lines.)

@tuckerhartland
Copy link
Author

@bartlettroscoe your suggestion for specifying the BLAS libraries fixed the issue, thank you so much for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants