wrf-model / WRF

The official repository for the Weather Research and Forecasting (WRF) model
Other
1.24k stars 681 forks source link

Should WRF/Makefile pass the NETCDF4_DEP_LIB to external/io_netcdf/makefile? #1945

Open Roadelse opened 10 months ago

Roadelse commented 10 months ago

I was compiling WRF and encounter the error of "undefined H5... " in producing external/io_netcdf/diffwrf. I find the detailed statement doesn't contain "-lhdf5_hl -lhdf5", and the NETCDF4_DEP_LIB in external/io_netcdf/makefile is empty. Since the NETCDF4_DEP_LIB in WRF/Makefile is an internal variable rather than environment variable, it will not be inherited when calling a "make" in some places. When I added NETCDF4_DEP_LIB=$(NETCDF4_DEP_LIB) to this statement ($(MAKE) ... ... diffwrf, near Line 927 of WRF/Makefile):

$(MAKE) NETCDFPATH="$(NETCDFPATH)" \
               FC="$(FC) $(FCBASEOPTS) $(PROMOTION) $(FCDEBUG) $(OMP)" RANLIB="$(RANLIB)" \
               CPP="$(CPP)" LDFLAGS="$(LDFLAGS)" TRADFLAG="$(TRADFLAG)" ESMF_IO_LIB_EXT="$(ESMF_IO_LIB_EXT)" \
               LIB_LOCAL="$(LIB_LOCAL)" \
               ESMF_MOD_DEPENDENCE="$(ESMF_MOD_DEPENDENCE)" AR="INTERNAL_BUILD_ERROR_SHOULD_NOT_NEED_AR" diffwrf; \

the compilation then work correctly.

Roadelse commented 10 months ago

I forgot to say, the version is WRF 4.5.1

weiwangncar commented 10 months ago

@islas Do you think PR#1935 would address this?

islas commented 10 months ago

@weiwangncar Not exactly but it is in the same scope of issue - NETCDF4_DEP_LIB as it is written right now tries to do a lot of extra logic that nc-config --libs already provides. Ideally we should only be using nc-config --libs to inform any netCDF linkage and not providing anything on top of that.

The way this affects this issue is that NETCDF4_DEP_LIB is being used as a stand-in for nc-config --libs in a particular area where -lnetcdf is being used.

Roadelse commented 10 months ago

considering the line in external/io_netcdf/makefile : LIBFFS = $(LIB_LOCAL) -L$(NETCDFPATH)/lib -lnetcdff -lnetcdf $(NETCDF4_DEP_LIB) however, the $(NETCDF4_DEP_LIB) just makes no sense since it is empty if we don't pass the variable to it, when calling this makefile from WRF/Makefile

islas commented 10 months ago

Going through PRs for v4.5.2, I realized #1923 should solve this. It also slightly addresses my previous point of better utilizing nc-config --libs as the main way to link in netCDF