Skip to content

Commit

Permalink
Darwin gfortranclang: Use C++ linker even for C programs
Browse files Browse the repository at this point in the history
This is needed to access functions from the C++ standard library;
otherwise, we get link errors when building with
ESMF_SHARED_LIB_BUILD=OFF. We could alternatively specify -lstdc++, and
that seems to solve the problem in at least some cases, but this may
lead to problems such as those with exception handling that we
encountered when linking with gfortran, which led us to use the C++
linker when linking Fortran programs. So this use of the C++ linker when
linking C programs is analogous to the use of the C++ linker when
linking Fortran programs with this compiler combination.

See #112 for details.
  • Loading branch information
billsacks committed Dec 12, 2022
1 parent 83715a0 commit 55a6394
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build_config/Darwin.gfortranclang.default/build_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ESMF_F90DEFAULT = gfortran
ESMF_F90LINKERDEFAULT = clang++
ESMF_CXXDEFAULT = clang++
ESMF_CDEFAULT = clang
ESMF_CLINKERDEFAULT = clang++
ESMF_CPPDEFAULT = clang -E -P -x c

ESMF_CXXCOMPILEOPTS += -x c++ -mmacosx-version-min=10.7 -stdlib=libc++
Expand Down Expand Up @@ -37,6 +38,7 @@ ESMF_F90DEFAULT = mpif90
ESMF_F90LINKERDEFAULT = mpiCC
ESMF_CXXDEFAULT = mpiCC
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpiCC
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_MPI3
Expand All @@ -47,6 +49,7 @@ ESMF_F90DEFAULT = mpif90
ESMF_F90LINKERDEFAULT = mpicxx
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
Expand All @@ -58,6 +61,7 @@ ESMF_F90DEFAULT = mpif90
ESMF_F90LINKERDEFAULT = mpicxx
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_CXXLINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.mpich3f90)
ESMF_F90LINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.mpich3f90)
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
Expand All @@ -69,6 +73,7 @@ ESMF_F90DEFAULT = mpif90
ESMF_F90LINKERDEFAULT = mpicxx
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
else
Expand All @@ -79,6 +84,7 @@ ESMF_F90DEFAULT = mpif77
ESMF_F90LINKERDEFAULT = mpic++
ESMF_CXXDEFAULT = mpic++
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpic++
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
Expand All @@ -96,6 +102,7 @@ ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_SIGUSR2
ESMF_F90LINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.openmpif90_forcxx $(ESMF_F90DEFAULT))
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
else
Expand Down

0 comments on commit 55a6394

Please sign in to comment.