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

Re: 980330: Help linking to C libraries



>To: address@hidden
>From: dan frankel <address@hidden>
>Subject: Help linking to C libraries
>Organization: Dept of Meteorology, Univ. of Utah
>Keywords: 199803312112.OAA00926

Hi Dan,

>       I am having trouble linking to netcdf libraries using a makefile
> to compile a c++ source code using CC on Solaris.  While I have no
> trouble using this same makefile to use the libnetcdf.a library to
> access FORTRAN netcdf procedures, I can't get the c routines to work.  I
> also linked to the library libnetcdf_c++.a, but I get the errors because
> the machine can't find the header files netcdf.h and netcdf.hh at
> compile time.  I know the libraries libnetcdf.a and libnetcdf_c++.a
> exist at the path as I have stated them in the makefile, do you have any
> ideas whay may be wrong?

It sounds like you are either missing the -I compiler flag or have the wrong
value for the -I flag on the compile line.

For example, when I am compiling the C++ program "nctst.cc" which
invokes functions from the netCDF DC++ library, I use something like

 CC -o nctst -I/upc/netcdf/include nctst.cc -L/upc/netcdf/lib -lnetcdf_c++ 
-lnetcdf

where I have the netCDF include files "netcdf.hh" and "netcdf.h"
installed in the directory "/upc/netcdf/include" and the libraries
"libnetcdf_c++.a" and "libnetcdf.a" installed in the directory
"/upc/netcdf/lib".

You could also do this in two separate steps like this:

 CC -c -I/upc/netcdf/include nctst.cc
 CC -o nctst nctst.o -L/upc/netcdf/lib -lnetcdf_c++ -lnetcdf

where the first compile step needs the include files so it looks where
-I specifies, and the second link step needs the .a libraries, so it
looks where -L specifies.

You may just need to set a Makefile macro for where the $(INCLUDES)
directory is, if your Makefile uses that macro.

I hope this helps.

--Russ

_____________________________________________________________________

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