[gdal-dev] Undefined reference with GDAL and netCDF support
henry wasker
henry.wasker at gmail.com
Mon Apr 28 08:33:04 PDT 2014
Hello,
I try to use a simple test program which must use GDAL and netcdf support.
This test is for constraints and specifications. Here's this code (main.cpp)
#include "gdal_priv.h"
#include "netcdfdataset.h"
using namespace std;
int main() {
netCDFDataset child;
}
For this, I have built GDAL (1.9.2) and netcdf (netcdf-c-4.3.2).
I have made 2 choices, firstly I built GDAL with the following option for
./configure :
./configure --prefix=/usr/local/gdal_without_ncdf/ --with-netcdf=no
After copying *netcdfdataset.h* and *netcdfdataset.cpp* in the current
directory ( from *~/gdal-1.9.2/frmts/netcdf/netcdfdataset.h* .) and once
*libgdal.so* and *libnetcdf.so* are built, I compile *the above
main.cpp*with the following Makefile :
# Makefile for test_gdal
CPP = g++
DIR_GDAL = /usr/local/gdal_without_netcdf
DIR_NETCDF = /usr/local/netcdf-gcc
INCLUDES = -I. -I$(DIR_GDAL)/include
LDFLAGS = -L$(DIR_GDAL)/lib -lgdal -L$(DIR_NETCDF)/lib -lnetcdf
RM = rm -f
all: test_gdal
test_gdal: main.o netcdfdataset.o
$(CPP) -o $@ $^ $(LDFLAGS)
%.o:%.cpp
$(CPP) -o $@ -c $< $(INCLUDES)
clean:
$(RM) test_gdal *.o
Everything compiles fine for this case.
But now, I tried another option, installing GDAL with a standard way :
./configure --prefix=/usr/local/gdal_standard_install/
I have noticed that "netcdf" is set to "yes" after this ./configure
So, I copied only netcdfdataset.h (without netcdfdata.cpp) in the current
directory for the "#include" of main.cpp and I compile with the following
script :
#!/bin/bash
GDAL_HOME=/usr/local/gdal_standard_install
g++ -I$GDAL_HOME/include -I. -c main.cpp
g++ -L$GDAL_HOME/lib -lgdal main.o -o test_gdal
Unfortunately, this compilation works fine only on *Debian/wheezy*. On *RedHat
6*, I have the following error :
main.cpp:(.text+0x73): undefined reference to
`netCDFDataset::~netCDFDataset()'
main.cpp:(.text+0x8c): undefined reference to
`netCDFDataset::~netCDFDataset()'
I don't understand why I have this error ; However, on *RedHat 6*, *the
symbol netCDFDataset* appears well with :
$ nm -C /usr/local/gdal_standard_install/lib/libgdal.so | grep -i
netcdfdataset
...
00000000003fac70 T netCDFDataset::netCDFDataset()
00000000003fac70 T netCDFDataset::netCDFDataset()
0000000000405d00 T netCDFDataset::~netCDFDataset()
0000000000405b90 T netCDFDataset::~netCDFDataset()
0000000000405b90 T netCDFDataset::~netCDFDataset()
...
If someone could see what's wrong
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140428/b04398bd/attachment.html>
More information about the gdal-dev
mailing list