Building ICON: -fPIC and -mcmodel=medium are not supported together

I am trying to install CMAQ 5.2.1 using PGI compiler (v18.10), libraries are netcdf 3.6.3, ioapi 3.1, mvapich2.

This is my compiler option in config_cmaq.csh file.

case pgi:
       #> Compiler Aliases and Flags
        setenv myFC mpif90
        #setenv myFC mpifort 
        setenv myCC pgcc
        setenv myLINK_FLAG #"-openmp"
        setenv myFSTD "-O3"
        setenv myDBG  "-O0 -g -Mbounds -Mchkptr -traceback -Ktrap=fp"

        setenv myFFLAGS "-Mfixed -Mextend -mcmodel=medium -tp=knl"
        setenv myFRFLAGS "-Mfree -Mextend -mcmodel=medium -tp=knl"

        setenv myCFLAGS "-O2"
        setenv extra_lib ""
        setenv mpi_lib "-lmpich"   #> -lmpich for mvapich or -lmpi for openmpi

        breaksw

With these option ,when i try to compile icon I got the error ’ -fPIC and -mcmodel=medium are not supported together’ BUT if I removed the option ‘mcmodel=medium’ then I can compile everything successfully?

How can I compile icon with ‘-mcmodel=medium’ option?

Where does the -fPIC come from? I don’t see it in the flags you show. (it should be used only for building shared (.so) libraries.)
Can you show us the exact compile-line together with error-messages?

Log file for icon build with error:

Compiler is set to pgi
set ICON_SRC = /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src
setenv REPOROOT /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src
set Mechs = /home01/a1009a01/CMAQ_5.2.1/CCTM/src/MECHS
set INPT = profile
set APPL = mcmodel
set EXEC = ICON_mcmodel_profile.exe
set CFG = ICON_mcmodel_profile.cfg
set CompileBLDMAKE
set CopySrc
set ModCommon = common
set ModType = profile
set ModMech = prof_data/saprc07t_ae6_aq
set Mechanism = saprc07tb_ae6_aq/
set Tracer = trac0
set FC = mpif90
set FP = mpif90
setenv BLDER /home01/a1009a01/CMAQ_5.2.1/UTIL/bldmake/bldmake_pgi.exe
set xLib_Base = /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi
set xLib_1 = ioapi/modules
set xLib_2 = ioapi/include_files
set xLib_4 = ioapi/lib
set FSTD = -O3
set DBG = -O0 -g -Mbounds -Mchkptr -traceback -Ktrap=fp
set F_FLAGS = -Mfixed -Mextend -mcmodel=medium -tp=knl
set F90_FLAGS = -Mfree -Mextend -mcmodel=medium -tp=knl
set CPP_FLAGS =
set LINK_FLAGS =
set LIB1 = -lioapi
set LIB2 = -lnetcdf
if ( ! -e /home01/a1009a01/CMAQ_5.2.1 || ! -e /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi ) then
echo     Model repository base path: /home01/a1009a01/CMAQ_5.2.1
    Model repository base path: /home01/a1009a01/CMAQ_5.2.1
echo                   library path: /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi
                  library path: /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi
if ( 0 ) then
set BLD_OS = `uname -s`
uname -s
if ( Linux != Linux ) then
set Bld = /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile
if ( ! -e /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile ) then
if ( ! -d /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile ) then
endif
cd /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile
if ( 1 ) then
/bin/cp -fp /home01/a1009a01/CMAQ_5.2.1/CCTM/src/MECHS/saprc07tb_ae6_aq//AE_saprc07tb_ae6_aq.nml /home01/a1009a01/CMAQ_5.2.1/CCTM/src/MECHS/saprc07tb_ae6_aq//GC_saprc07tb_ae6_aq.nml /home01/a1009a01/CMAQ_5.2.1/CCTM/src/MECHS/saprc07tb_ae6_aq//NR_saprc07tb_ae6_aq.nml /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile
/bin/cp -fp /home01/a1009a01/CMAQ_5.2.1/CCTM/src/MECHS/trac0/Species_Table_TR_0.nml /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile
else
set Cfile = ICON_mcmodel_profile.cfg.bld
set quote = "
echo
echo model       ICON_mcmodel_profile.exe;
echo
echo repo        /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src;
echo
echo mechanism   saprc07tb_ae6_aq/;
echo
echo lib_base    /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi;
echo
echo lib_1       ioapi/modules;
echo
echo lib_2       ioapi/include_files;
echo
echo lib_4       ioapi/lib;
echo
set text = "";
echo cpp_flags   "";
echo
echo f_compiler  mpif90;
echo
echo fstd        "-O3";
echo
echo fstd        "-O3";
echo
echo dbg         "-O0 -g -Mbounds -Mchkptr -traceback -Ktrap=fp";
echo
echo f_flags     "-Mfixed -Mextend -mcmodel=medium -tp=knl";
echo
echo f90_flags   "-Mfree -Mextend -mcmodel=medium -tp=knl";
echo
echo link_flags  "";
echo
echo ioapi       "-lioapi";
echo
echo netcdf      "-lnetcdf ";
echo

set text=// mechanism:
echo // mechanism: saprc07tb_ae6_aq/
echo // project repository: /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src
echo
set text = common
echo // required common
echo Module common;
echo
set text = profile, m3conc, tracer
echo // options are profile, m3conc, tracer
echo Module profile;
echo
set text = cb05, saprc99, saprc07t
echo // options are cb05, saprc99, saprc07t
echo Module prof_data/saprc07t_ae6_aq;
echo
if ( 0 ) then
unalias mv rm
if ( 1 || ! -f /home01/a1009a01/CMAQ_5.2.1/UTIL/bldmake/bldmake_pgi.exe ) then
cd /home01/a1009a01/CMAQ_5.2.1/UTIL/bldmake/scripts
./bldit_bldmake.csh
endif
set Blder = /home01/a1009a01/CMAQ_5.2.1/UTIL/bldmake/bldmake_pgi.exe -serial -verbose
cd /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile
if ( 0 ) then
if ( 1 ) then
/home01/a1009a01/CMAQ_5.2.1/UTIL/bldmake/bldmake_pgi.exe -serial -verbose ICON_mcmodel_profile.cfg.bld
REPOROOT set to:/home01/a1009a01/CMAQ_5.2.1/PREP/icon/src

Model set to ICON_mcmodel_profile.exe
Repository set to /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src
Mechanism set to saprc07tb_ae6_aq/
LIB_BASE set to /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi
LIB_1 set to ioapi/modules
LIB_2 set to ioapi/include_files
LIB_4 set to ioapi/lib
CPP_FLAGS set to
F_COMPILER set to mpif90
FSTD set to -O3
DBG set to -O0 -g -Mbounds -Mchkptr -traceback -Ktrap=fp
f_flags set to -Mfixed -Mextend -mcmodel=medium -tp=knl
f90_flags set to -Mfree -Mextend -mcmodel=medium -tp=knl
LINK_FLAGS set to
IOAPI set to -lioapi
NETCDF set to -lnetcdf


Building file list for module common
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/CGRID_SPCS.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/findex.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/gc_spc_map.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/get_envlist.f added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/HGRD_DEFN.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/icon.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/IC_PARMS.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/lat_lon.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/lr_interp.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/lst_spc_map.F added to make list
file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/ngc_spc_map.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/opn_ic_file.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/setup_logdev.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/subhdomain.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/UTILIO_DEFN.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/common/VGRD_DEFN.F added to make list


Building file list for module profile
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/profile/prof_driver.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/profile/prof_icout.F added to make list
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/profile/prof_vinterp.F added to make list


Building file list for module prof_data/saprc07t_ae6_aq
  file /home01/a1009a01/CMAQ_5.2.1/PREP/icon/src/prof_data/saprc07t_ae6_aq/ic_profile_SAPRC07T.dat added to make list

Determining global module files
  file CGRID_SPCS.F determined to be global
  file HGRD_DEFN.F determined to be global
  file IC_PARMS.F determined to be global
  file UTILIO_DEFN.F determined to be global
  file VGRD_DEFN.F determined to be global

Generating Makefile

  Compilers defined
  CPP Flags defined
  Libraries defined
  Includes defined
  Objects defined
  Make rules defined

 file,nfields-1 CGRID_SPCS.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F


 file,nfields-1 gc_spc_map.F             3
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             3 CGRID_SPCS CGRID_SPCS.F


 file,nfields-1 HGRD_DEFN.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 icon.F             6
 modName,modFile             2 HGRD_DEFN HGRD_DEFN.F
 modName,modFile             3 VGRD_DEFN VGRD_DEFN.F
 modName,modFile             4 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             5 CGRID_SPCS CGRID_SPCS.F
 modName,modFile             6 IC_PARMS IC_PARMS.F


 file,nfields-1 lat_lon.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 lr_interp.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 lst_spc_map.F             4
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             3 CGRID_SPCS CGRID_SPCS.F
 modName,modFile             4 IC_PARMS IC_PARMS.F

 file,nfields-1 ngc_spc_map.F             4
 modName,modFile  mpif90 -c -Mfixed -Mextend -mcmodel=medium -tp=knl -O3 -I /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi/ioapi/modules -I /home01/a1009a01/CMAQ_5.2.1/lib/x86_64/pgi/ioapi/include_files   UTILIO_DEFN.F
pgfortran-Error-Switches -fPIC and -mcmodel=medium are not supported together
make: *** [UTILIO_DEFN.o] Error 1
FORTRAN STOP
           2 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             3 CGRID_SPCS CGRID_SPCS.F
modName,modFile             4 IC_PARMS IC_PARMS.F

 file,nfields-1 opn_ic_file.F             6
 modName,modFile             2 HGRD_DEFN HGRD_DEFN.F
 modName,modFile             3 VGRD_DEFN VGRD_DEFN.F
 modName,modFile             4 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             5 CGRID_SPCS CGRID_SPCS.F
 modName,modFile             6 IC_PARMS IC_PARMS.F

 file,nfields-1 setup_logdev.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 subhdomain.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 UTILIO_DEFN.F             3
 modName                     2 M3UTILIO  -------------
 modName                     3 PARUTILIO  -------------

 file,nfields-1 VGRD_DEFN.F             2
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F

 file,nfields-1 prof_driver.F             4
 modName,modFile             2 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             3 CGRID_SPCS CGRID_SPCS.F
 modName,modFile             4 IC_PARMS IC_PARMS.F

 file,nfields-1 prof_icout.F             5
 modName,modFile             2 HGRD_DEFN HGRD_DEFN.F
 modName,modFile             3 VGRD_DEFN VGRD_DEFN.F
 modName,modFile             4 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             5 IC_PARMS IC_PARMS.F

 file,nfields-1 prof_vinterp.F             5
 modName,modFile             2 HGRD_DEFN HGRD_DEFN.F
 modName,modFile             3 VGRD_DEFN VGRD_DEFN.F
 modName,modFile             4 UTILIO_DEFN UTILIO_DEFN.F
 modName,modFile             5 IC_PARMS IC_PARMS.F

  USE/MODULE dependencies defined

Makefile generated
**ERROR** while running make command

else
endif
mv Makefile Makefile.pgi
ln -s Makefile.pgi Makefile
if ( 0 != 0 ) then
if ( -e /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile/ICON_mcmodel_profile.cfg ) then
mv ICON_mcmodel_profile.cfg.bld /home01/a1009a01/CMAQ_5.2.1/PREP/icon/scripts/BLD_ICON_mcmodel_profile/ICON_mcmodel_profile.cfg
exit