Since CMake 3.24.0, the linker overhaul (or other release changes) have had the effect of omitting “-lc++” when AppleClang is used with GNU Fortran to make a Fortran main executable with C++ library.
I have a MWE at CMake C++ library and Fortran main program: multiple issues · GitHub
The workaround I applied that fixes it was the following. Is this just a necessary workaround, or is there a more canonical way to do this?
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_GENERATOR STREQUAL "Unix Makefiles")
# otherwise failed to link since -lc++ is missing
set(link_lang CXX)
else()
set(link_lang Fortran)
endif()
set_property(TARGET main_f PROPERTY LINKER_LANGUAGE ${link_lang})