FortranCInterface: cmake-3.19.4 fails to find fortran libraries on FreeBSD
EDIT: Discussion below concluded that this is a duplicate of #21408 (closed), which is fixed by !5483 (merged) for 3.20, not for 3.19.
Original Description
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(Dakota LANGUAGES C CXX Fortran)
INCLUDE(FortranCInterface)
FortranCInterface_VERIFY(CXX)
Command:
F77="gfortran10" FC="gfortran10" FFLAGS="-O -fallow-argument-mismatch -Wl,-rpath=/usr/local/lib/gcc10" FCFLAGS="-Wl,-rpath=/usr/local/lib/gcc10" XDG_DATA_HOME=/usr/ports/math/dakota/work XDG_CONFIG_HOME=/usr/ports/math/dakota/work HOME=/usr/ports/math/dakota/work PATH=/usr/ports/math/dakota/work/.bin:/home/yuri/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin SHELL=/bin/sh CONFIG_SHELL=/bin/sh \
cmake \
-DCMAKE_C_COMPILER:STRING="cc" -DCMAKE_CXX_COMPILER:STRING="c++" -DCMAKE_EXE_LINKER_FLAGS:STRING=" -lexecinfo -Wl,-rpath=/usr/local/lib/gcc10 -L/usr/local/lib/gcc10 -B/usr/local/bin -fstack-protector-strong " -DCMAKE_MODULE_LINKER_FLAGS:STRING=" -lexecinfo -Wl,-rpath=/usr/local/lib/gcc10 -L/usr/local/lib/gcc10 -B/usr/local/bin -fstack-protector-strong " -DCMAKE_SHARED_LINKER_FLAGS:STRING=" -lexecinfo -Wl,-rpath=/usr/local/lib/gcc10 -L/usr/local/lib/gcc10 -B/usr/local/bin -fstack-protector-strong "
Output:
CMake Error at /usr/local/share/cmake/Modules/FortranCInterface.cmake:383 (message):
The Fortran compiler:
/usr/local/bin/gfortran10
and the CXX compiler:
/usr/bin/c++
failed to compile a simple test project using both languages. The output
was:
Change Dir: /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX
Run Build Command(s):/usr/local/bin/gmake VerifyFortranC && /usr/local/bin/cmake -S/usr/local/share/cmake/Modules/FortranCInterface/Verify -B/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/gmake -f CMakeFiles/Makefile2 VerifyFortranC
gmake[1]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/cmake -S/usr/local/share/cmake/Modules/FortranCInterface/Verify -B/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles 6
/usr/local/bin/gmake -f CMakeFiles/Makefile2 CMakeFiles/VerifyFortranC.dir/all
gmake[2]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/depend
gmake[3]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
cd /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortran.dir/DependInfo.cmake
gmake[3]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/build
gmake[3]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
gmake[3]: Nothing to be done for 'CMakeFiles/VerifyFortran.dir/build'.
gmake[3]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
[ 33%] Built target VerifyFortran
/usr/local/bin/gmake -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/depend
gmake[3]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
cd /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortranC.dir/DependInfo.cmake
gmake[3]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/build
gmake[3]: Entering directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
[ 50%] Building C object CMakeFiles/VerifyFortranC.dir/main.c.o
/usr/bin/cc -DVERIFY_CXX -I/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX -O3 -DNDEBUG -o CMakeFiles/VerifyFortranC.dir/main.c.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/main.c
[ 66%] Building C object CMakeFiles/VerifyFortranC.dir/VerifyC.c.o
/usr/bin/cc -DVERIFY_CXX -I/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX -O3 -DNDEBUG -o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/VerifyC.c
[ 83%] Building CXX object CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o
/usr/bin/c++ -DVERIFY_CXX -I/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX -O3 -DNDEBUG -o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/VerifyCXX.cxx
[100%] Linking CXX executable VerifyFortranC
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortranC.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/VerifyFortranC.dir/main.c.o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -o VerifyFortranC -L/usr/local/bin -L/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.1/10.2.0 -L/usr/local/x86_64-portbld-freebsd12.1/lib libVerifyFortran.a -lgfortran -lssp_nonshared -lquadmath
ld: error: unable to find library -lgfortran
ld: error: unable to find library -lquadmath
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/VerifyFortranC.dir/build.make:137: VerifyFortranC] Error 1
gmake[3]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
gmake[2]: *** [CMakeFiles/Makefile2:100: CMakeFiles/VerifyFortranC.dir/all] Error 2
gmake[2]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
gmake[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/VerifyFortranC.dir/rule] Error 2
gmake[1]: Leaving directory '/usr/ports/math/dakota/PR21408/CMakeFiles/FortranCInterface/VerifyCXX'
gmake: *** [Makefile:140: VerifyFortranC] Error 2
Call Stack (most recent call first):
CMakeLists.txt:5 (FortranCInterface_VERIFY)
This may or may not be related to #21408 (closed) 21408 was created while investigating a similar issue in the same project (Dakota).
Edited by Brad King