Re: [netcdfgroup] help compling c++ code with netcdf.

  • To: "Ed Hartnett" <ed@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdfgroup] help compling c++ code with netcdf.
  • From: "Tang, Jinyun" <tang16@xxxxxxxxxx>
  • Date: Thu, 2 Apr 2009 10:21:02 -0400
Thanks much. I solved the problem.

Ph.D student
Earth and Atmosphric Sciences Department
Ecosystems and Biogeochemical Dynamics Laboratory
Purdue University CIVIL 3250, 550 Stadium Mall Drive West Lafayette, IN, 
47907-2051
http://web.ics.purdue.edu/~tang16/



-----Original Message-----
From: Ed Hartnett [mailto:ed@xxxxxxxxxxxxxxxx]
Sent: Thu 4/2/2009 7:45 AM
To: Tang, Jinyun
Cc: netcdfgroup@xxxxxxxxxxxxxxxx
Subject: Re: [netcdfgroup] help compling c++ code with netcdf.
 
"Tang, Jinyun" <tang16@xxxxxxxxxx> writes:

> Hi,
>   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.
>   Jinyun
>
> Ph.D student
> Earth and Atmosphric Sciences Department
> Ecosystems and Biogeochemical Dynamics Laboratory
> Purdue University CIVIL 3250, 550 Stadium Mall Drive West Lafayette, IN,
> 47907-2051
> [1]http://web.ics.purdue.edu/~tang16/


You must add -lnetcdf to the LDFLAGS (not LFLAGS). OFLAGS is
meaningless - set these in CFLAGS instread.

Good luck!

Ed
  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: