[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 19990721: NetCDF: Calling nccreate - Error



>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