[gmx-users] help needed for using xdr library

Jussi Lehtola jussi.lehtola at helsinki.fi
Mon Aug 17 19:46:55 CEST 2009

On Mon, 2009-08-17 at 09:41 -0400, Kun Huang wrote:
> Hello everyone:
> Recently I am trying to use the xdr library downloaded from gromacs
> org to read xtc files. However when I link my program with the library
> there is an error. When I ran the make test, all the tests were
> passed. Thus I think that the library should work just I don't know
> how to link the program. I tried to read the makefile in the library
> but it is very 
> complicated and beyond my scope. My program is very simple:
> //source file of cm.cc
> #include"/home/kun/xdr/include/xdrfile/xdrfile_xtc.h"

> g++ cm.o /home/kun/xdr/lib/libxdrfile.a there is a link error:
> cm.o: In function `main':
> cm.cc:(.text+0x2d): undefined reference to `read_xtc_natoms(char*,
> int*)'
> collect2: ld returned 1 exit status
> Could anyone help me? 

This is the result of non-matching name spaces.

You're using C++, and xdrfile is written in C. Instead of
#include <xdrfile/xdrfile_xtc.h>

you need to use

extern C {
#include <xdrfile/xdrfile.h>

to get the name spaces correct.
Jussi Lehtola, FM, Tohtorikoulutettava
Fysiikan laitos, Helsingin Yliopisto
jussi.lehtola at helsinki.fi, p. 191 50632
Mr. Jussi Lehtola, M. Sc., Doctoral Student
Department of Physics, University of Helsinki, Finland
jussi.lehtola at helsinki.fi

More information about the gromacs.org_gmx-users mailing list