Menu

Error Building NCO 4.6.6 with GCC 7.1

Developers
2017-05-08
2017-05-08
  • Matthew Thompson

    All, or, well, Charlie,

    I recently got GCC 7.1 installed on a local box and decided to build my Baselibs which includes NCO 4.6.0. All seems to build okay (barring an issue with antlr since GCC 7.1 no longer supplies gcj, so I need javac), but when I get to NCO, it dies at:

    mpic++ -DHAVE_CONFIG_H -I. -I../..  -I./ -I../nco -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/netcdf -DgFortran -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/ -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/zlib -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/szlib -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/jpeg -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/hdf5 -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/hdf -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/uuid -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/netcdf -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/udunits2 -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/gsl -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/antlr -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/netcdf -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux//include -DgFortran  -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/zlib    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/szlib    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/jpeg    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/hdf5    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/hdf    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/uuid    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/netcdf    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/udunits2    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/gsl    -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/antlr   -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/netcdf  -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/antlr -I/ford1/share/gmao_SIteam/Baselibs/ESMA-Baselibs-5.0.4/x86_64-unknown-linux-gnu/gfortran_7.1.0-openmpi_2.1.0/Linux/include/gsl  -g -O2 -MT fmc_all_cls.o -MD -MP -MF .deps/fmc_all_cls.Tpo -c -o fmc_all_cls.o fmc_all_cls.cc
    fmc_all_cls.cc: In member function ‘var_sct* vlist_cls::atoi_fnd(bool&, std::vector<antlr::ASTRefCount<antlr::AST> >&, fmc_cls&, ncoTree&)’:
    fmc_all_cls.cc:4193:21: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
              char *pend='\0';
                         ^~~~
    fmc_all_cls.cc:4214:21: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
              char *pend='\0';
                         ^~~~
    make[4]: *** [fmc_all_cls.o] Error 1
    

    I'm using mpic++ because I build HDF5 with parallel support, so the toolchain that uses netCDF needs it. I first checked my antlr install because I saw that the error referenced antlr, but that wasn't the issue. I also tried compiling with GCC 6.3.0 (and a slightly older Open MPI) and that does work (with either javac available or not).

    So, I'm at the point where I'm thinking this is due to some new Standards strictness in GCC 7.1.0. A glance around the internet seems to say that char* requires double quotes and char single, but double quotes imply null termination and your string is only null...brain asplode. Still, I made the dumb fix of double quotes instead of single quotes:

    diff --git a/src/nco++/fmc_all_cls.cc b/src/nco++/fmc_all_cls.cc
    index fb0f88c..e8546f5 100644
    --- a/src/nco++/fmc_all_cls.cc
    +++ b/src/nco++/fmc_all_cls.cc
    @@ -4190,7 +4190,7 @@ var_sct *vlist_cls::push_fnd(bool &is_mtd, std::vector<RefAST> &vtr_args, fmc_cl
       {
          case PATOI: 
            {          
    -         char *pend='\0';
    +         char *pend="\0";
              nco_int iout;
              iout=0; 
    
    @@ -4211,7 +4211,7 @@ var_sct *vlist_cls::push_fnd(bool &is_mtd, std::vector<RefAST> &vtr_args, fmc_cl
    
          case PATOL: 
            {          
    -         char *pend='\0';
    +         char *pend="\0";
              nco_int64 lout;
              lout=0; 
    

    and I don't get an error, so it all works:

    fmc_all_cls.cc: In member function ‘var_sct* vlist_cls::atoi_fnd(bool&, std::vector<antlr::ASTRefCount<antlr::AST> >&, fmc_cls&, ncoTree&)’:
    fmc_all_cls.cc:4193:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
              char *pend="\0";
                         ^~~~
    fmc_all_cls.cc:4214:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
              char *pend="\0";
                         ^~~~
    mv -f .deps/fmc_all_cls.Tpo .deps/fmc_all_cls.Po
    

    though I do now get warnings (but warning > error). Since my C++ knowledge is "I can read it and sometimes hack codes to add a cout for debugging", it is possible and highly probable I broke whatever this is doing. As I don't know how to trigger whatever code I just altered (I only recently enabled building of ncap2 because I wanted to play around with it; it looks useful!), I don't know if I just broke everything.

    So, Charlie, do you know a "correct" fix for this? Or do you suspect this is a GCC 7.1.0 bug that I should report? Or should I just pass in -fpermissive in my configure for NCO if using GCC 7.1.0 and be done with it?

    Matt

     
  • Matthew Thompson

    Side note: If I set CXXFLAGS=-fpermissive for NCO configuration and building, I do get past this as well. I can easily add a make rule for 'if gfortran 7', so that's a workaround for now.

     
    • Charlie Zender

      Charlie Zender - 2017-05-08

      Matthew, thank you for the GCC 7 compile report. The initialization line that causes problems is weird. Henry, please consider rewriting these initializations as Matthew suggests, or even something more GCC7-friendly. I think GCC7 implements ISO C++ 2011 and drops support for a deprecated feature that now triggers an error instead. It's unclear to me what the code in question does or I would try to re-write it myself, but my inclination is that the initialization should be

      char *pend=NULL;
      

      Since pend performs same role as sng_cnv_rcd in the rest of NCO. We need NCO to be GCC7-compliant...

       

Log in to post a comment.