This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: "John W. Hill" <address@hidden> >Subject: NetCDF: Calling nccreate - Error >Organization: NOAA Aircraft Operations Center >Keywords: 199907211402.IAA22278 netCDF RedHat Linux Hi John, In the above, you wrote: > I hope you can help. I am new to using netCDF libraries. I'm trying some > basic get started stuff here. See my short program below and then see the > results of my compile. What can am I doing wrong here? I am running a RedHat > Linux 6.0 on a PC and using gcc version egcs-2.91.66. Thanks in advance. > > My source > --------------------- > #include <stdio.h> > #include "netcdf.h" > > main(void) { > int fd=-1; > char file[1024]; > > strcpy(file,"mytest"); > fd = nccreate(file,NC_NOCLOBBER); > } > ------------------------ > > > > Compile Results > ------------------------------------------------------------- > [johnh@number2 ~] gcc mynetcdf.c > /tmp/ccyOcOdl.o: In function `main': > /tmp/ccyOcOdl.o(.text+0x2e): undefined reference to `nccreate' > collect2: ld returned 1 exit status On the gcc line, you've neglected to indicate where the "netcdf.h" file is to found, using the "-I" flag, and where the netCDF library is installed, using the "-L" and "-l" flags. These are necessary so gcc can find the include file and library to link in functions like nccreate that are part of netCDF library. For example, if you have installed the library in "/local/lib/libnetcdf.a" and the include file in "/local/include/netcdf.h", then your compile line should like something like: gcc -I/local/include mynetcdf.c -L/local/lib -lnetcdf which will compile the program and store the result in an executable named "a.out". If you haven't yet installed the netCDF library (with "make install"), but instead just compiled it (with "make all"), then the library is currently in some directory such as, for example, "/tmp/netcdf-3.4/src/libsrc/libnetcdf.a". In this case, you will need to compile and link it with something like: gcc -I/tmp/netcdf-3.4/src/libsrc/l mynetcdf.c -L/tmp/netcdf-3.4/src/libsrc -lnetcdf which is more cumbersome. If you want to not have to specify the include file directory or library directory, you have to install netcdf.h and libnetcdf.a in special directories that are automatically searched by your gcc compiler. These depend on where gcc is installed. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu