Problem linking netcdf - Undefined References...

L

lars.uffmann

Hi - since my Suse 10.1 didn't have netcdf support enabled by default,
I downloaded the sources from
http://www.unidata.ucar.edu/software/netcdf/ then did
../configure --prefix=/usr
make
make test --> succeeded
make extra_test --> succeeded
make install

In my /usr/include I now have the files
netcdfcpp.h
netcdf.h
netcdf.hh

and in /usr/lib I have
libnetcdf.a
libnetcdf_c++.a

And while now my program using netcdf compiles fine, the linker will
complain about undefined references - I tried compiling with
g++ -o test test.cpp
g++ -o test test.cpp -lnetcdf
g++ -o test test.cpp -lnetcdf_c++
g++ -o test test.cpp -lnetcdf -lnetcdf_c++
and with
g++ -o test test.cpp /usr/lib/libnetcdf.a
g++ -o test test.cpp /usr/lib/libnetcdf_c++.a
g++ -o test test.cpp /usr/lib/libnetcdf.a /usr/lib/libnetcdf_c++.a
also
g++ -o test -I/usr/include -L/usr/lib test.cpp

All of them fail :(

Program test.cpp:
--------------------
#include <netcdf.hh>

using namespace std;

int main( int argc, char ** argv )
{
NcFile file("out.txt", NcFile::Replace);
return 0;
}
------------------------

Anyone able to help?

Regards,

Lars
 
H

Howard

Hi - since my Suse 10.1 didn't have netcdf support enabled by default,
I downloaded the sources from
http://www.unidata.ucar.edu/software/netcdf/ then did
./configure --prefix=/usr
make
make test --> succeeded
make extra_test --> succeeded
make install

In my /usr/include I now have the files
netcdfcpp.h
netcdf.h
netcdf.hh

and in /usr/lib I have
libnetcdf.a
libnetcdf_c++.a

And while now my program using netcdf compiles fine, the linker will
complain about undefined references - I tried compiling with
g++ -o test test.cpp
g++ -o test test.cpp -lnetcdf
g++ -o test test.cpp -lnetcdf_c++
g++ -o test test.cpp -lnetcdf -lnetcdf_c++
and with
g++ -o test test.cpp /usr/lib/libnetcdf.a
g++ -o test test.cpp /usr/lib/libnetcdf_c++.a
g++ -o test test.cpp /usr/lib/libnetcdf.a /usr/lib/libnetcdf_c++.a
also
g++ -o test -I/usr/include -L/usr/lib test.cpp

All of them fail :(

Program test.cpp:
--------------------
#include <netcdf.hh>

using namespace std;

int main( int argc, char ** argv )
{
NcFile file("out.txt", NcFile::Replace);
return 0;
}

For problems with someone's library, you need to contact the people who
created or are supporting that library. For linker problems, you need to
contact the compiler vendor or ask in a newsgroup dedicated to that
compiler, or perhaps even the OS. There's nothing here related to the C++
language, which is what we discuss here.

-Howard
 
L

lars.uffmann

Howard said:
For problems with someone's library, you need to contact the people who
created or are supporting that library. For linker problems, you need to
contact the compiler vendor or ask in a newsgroup dedicated to that
compiler, or perhaps even the OS. There's nothing here related to the C++
language, which is what we discuss here.

For just stating that, you didn't need to include a full quote...

Since there is no netcdf newsgroup, and this seems to be a general
library inclusion problem with the gnu compiler, I was hoping someone
here knows the problem and would be able to direct me to a solution.
And I still hope that. Telling me I am off-topic when there is no 100%
on-topic newsgroup didn't really help.

Regards,

Lars
 
H

Howard

For just stating that, you didn't need to include a full quote...

Since there is no netcdf newsgroup, and this seems to be a general
library inclusion problem with the gnu compiler, I was hoping someone
here knows the problem and would be able to direct me to a solution.
And I still hope that. Telling me I am off-topic when there is no 100%
on-topic newsgroup didn't really help.

You could try a newsgroup with "gnu" in the name.
 
L

Lars Uffmann

And while now my program using netcdf compiles fine, the linker will
complain about undefined references - I tried compiling with
[...]
g++ -o test test.cpp -lnetcdf -lnetcdf_c++

Just for the record, the problem was in the order of supplying the
libraries-to-link on the command line.
The correct order is
g++ -o test test.cpp -lnetcdf_c++ -lnetcdf

Reason:
http://webpages.charter.net/ppluzhnikov/linker.html


This works fine and solved the problem, thanks to
gnu.g++.help :)


Regards,

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top