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

[netCDF #DMM-591072]: [netcdfgroup] help compling c++ code with



Hi Jinyun,

> I'm new to netcdf. But I'm sure I installed netcdf4 correctly on my computer,
as it passed all the test. However, when I'm trying to link my .o files, I
received a chunk of errors such as:
> /usr/local/netcdf/netcdf-4.0/cxx/netcdf.cpp:172: undefined reference to
`nc_def_var'
> /usr/local/lib/libnetcdf_c++.a(netcdf.o): In function `NcFile::sync()':
> /usr/local/netcdf/netcdf-4.0/cxx/netcdf.cpp:275: undefined reference to
`nc_sync'
>
> The command I used for linking is as below: (assuming .o files are ready)
> #Specify the compiler
> CC =  g++
>
> #Specify the compiling flags
> CFLAGS = -c -I/usr/local/include
> #OFLAGS = -g -o
> OFLAGS = -O3 -o
> LFLAGS = -L/usr/local/lib -lnetcdf_c++
>
> OBJS =              \
> global_fun.o
>
> XOBJ = ncextra.o
>
#=============================================================================
> # Executable: xhydstmtem
>
#=============================================================================
> ncextra : $(OBJS) $(XOBJ)
> $(CC) $(OFLAGS) ncextra $(OBJS) $(XOBJ) $(LFLAGS)
>
#=============================================================================
>
> Can anyone help me with this? I appreciate it.

You need to add -lnetcdf after the -lnetcdf_c++ option, because the
C++ library calls the C library.  You may find other libraries are needed
as well, if you built netCDF with --enable-netcdf-4, because the netCDF
C library calls an HDF5 library and compression library as well.  If you
built without the --enable-netcdf-4 option to configure, then it may
be enough to just add -lnetcdf.

--Russ


Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: DMM-591072
Department: Support netCDF
Priority: Normal
Status: Closed