netcdf-fortran icon indicating copy to clipboard operation
netcdf-fortran copied to clipboard

configure: error: netcdf.h could not be found. Please set CPPFLAGS.

Open nightkeo opened this issue 7 years ago • 9 comments

Hello!

I tried install NetCDF on Ubuntu (gcc and gfortran was installed: sudo apt-get install gcc gfortran) and received error configure:

error: netcdf.h could not be found. Please set CPPFLAGS. as I found (https://www.unidata.ucar.edu/software/netcdf/docs/building_netcdf_fortran.html), I set:

NCDIR=/usr/local export LD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH} NFDIR=/usr/local CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib
./configure --prefix=${NFDIR}

and it didn't solve my problem.

nightkeo avatar Dec 28 '17 13:12 nightkeo

I'm saw the same problem as well. I used the following and ended up having success:

$ export CPPFLAGS=-I${NCDIR}/include
$ export LDFLAGS=-L${NCDIR}/lib
$ ./configure --enable-parallel-tests --prefix=${NFDIR}

I'm not sure why exporting matters here.

glemieux avatar Apr 19 '19 17:04 glemieux

Interesting; @glemieux I assume the alternative, specifying CPPFLAGS/LDFLAGS on the same line configure didn't work? What platform were you on? I'd like to try to duplicate this and figure out where the issue is.

WardF avatar Apr 19 '19 22:04 WardF

I'm working on an pop-os, and ubuntu distribution. Let me know if you'd like any other information from the nc-config output or related.

Not sure if this is relevant, but I did have success running the commands on a single line, but for the NeetCDF-C install.

glemieux avatar Apr 19 '19 22:04 glemieux

I had the same problem and exporting fixed it for me. Why isn't this in the build guide?

simon-Leary42 avatar Jan 24 '22 17:01 simon-Leary42

Because this is basic Unix shell knowledge.

A shell variable that is not exported does not have any effect except for the line you use it. So you can do:

export CPPFLAGS='something'
./configure

Or you can do:

CPPFLAGS='something' ./configure

edwardhartnett avatar Jan 26 '22 12:01 edwardhartnett

The code, copy pasted out of the build guide, didn't work. Didn't that guy have basic shell knowledge? When this error came up, configure looked for netcdf in other standard locations, found something in /usr/bin, and threw a completely unrelated error. So the only way to uncover this error which was a quick fix was to uninstall netcdf from an active HPC cluster using the package manager. I just wonder if there's a way to save the next guy the trouble.

simon-Leary42 avatar Jan 26 '22 14:01 simon-Leary42

This is probably worth making explicit in the shell guide, regardless of basic knowledge or not, as a lot of folk seem to encounter it, and particularly if they are following written instructions and aren't seasoned *nix users, the verbose information will be useful. I'll try to get that updated :).

WardF avatar Feb 08 '22 17:02 WardF

Hello There, I am trying to compile netcdf-c-4.7.2 and netcdf-fortran-4.5.2 on a Red Hat Enterprise Linux v9.1 machine. I am running into this same error ‘configure: error: netcdf.h could not be found. Please set CPPFLAGS.’ I configured netcdf-c-4.7.2 with the following command: ./configure --prefix=$DIR/netcdf --disable-netcdf-4 --disable-dap

After install I found the ‘netcdf.h’ file located at ‘/netcdf/include/netcdf.h’. I set my CPPFLAGS using the following: export CPPFLAGS="-I$DIR/netcdf/include"

I attempted to configure netcdf-fortran-4.5.2 with the following command: ./configure --prefix=$DIR/netcdf

After all of that, I am still running into the same error. Can anyone please advise? Best, J

jk-water avatar Dec 03 '22 00:12 jk-water

I agree that the understanding of setting environment vars is very important but sadly not widespread among the scientific computing world. I remember this was confusing for me, many (many!) years ago. So I sympathize.

Confusion is compounded by the fact that there are different command line shells in common use, and setting environment variables is different in different shells. Find out what shell you are using with:

echo $SHELL

Then spend 15 minutes learning how to set and use environment variables in your shell. Once you understand that, come back and try netCDF again, and hopefully it will be more clear. To compile netcdf-c you usually set the CPPFLAGS to point to the HDF5 include directory, and the LDFLAGS to point to the HDF5 library directory (unless disabling netcdf-4). On my machine (using the bash shell), configuring netcdf-c looks like this:

CPPFLAGS=-I/usr/local/hdf5-1.12.1/include LDFLAGS=/usr/local/hdf5-1.12.1/lib ./configure

When building netcdf-fortran you set the CPPFLAGS to find the netcdf-c include directory and the LDFLAGS to find the netcdf-c lib directory.

Some important advice:

  • Use the latest netcdf-c and netcdf-fortran. netcdf-c-4.7.2 is pretty old
  • can you use netcdf-c-4.9.0?
  • When configure reports a problem, open the config.log file and search for that exact error message to see exactly what went wrong. Ignore everything else in config.log.
  • If you have problems, submit an issue to netcdf-c or netcdf-fortran on GitHub with the complete command(s) you are using, the full output of configure, and the config.log file.

Please don't just summarize, as has been done in this thread. Post the complete output of configure and the config.log file.

Good luck!

On Fri, Dec 2, 2022 at 5:07 PM jk-water @.***> wrote:

Hello There, I am trying to compile netcdf-c-4.7.2 and netcdf-fortran-4.5.2 on a Red Hat Enterprise Linux v9.1 machine. I am running into this same error ‘configure: error: netcdf.h could not be found. Please set CPPFLAGS.’ I configured netcdf-c-4.7.2 with the following command: ./configure --prefix=$DIR/netcdf --disable-netcdf-4 --disable-dap

After install I found the ‘netcdf.h’ file located at ‘/netcdf/include/netcdf.h’. I set my CPPFLAGS using the following: export CPPFLAGS="-I$DIR/netcdf/include"

I attempted to configure netcdf-fortran-4.5.2 with the following command: ./configure --prefix=$DIR/netcdf

After all of that, I am still running into the same error. Can anyone please advise? Best, J

— Reply to this email directly, view it on GitHub https://github.com/Unidata/netcdf-fortran/issues/73#issuecomment-1335976509, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCSXXCK33AOWW5RI42ZBJ3WLKFMRANCNFSM4EJZJMKA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

edhartnett avatar Dec 04 '22 14:12 edhartnett