Re: [netcdfgroup] Linker option ordering when linking to HDF5

It is more complicated with netCDF4 but there is the nc-config tool that should 
generate what you need for linking and in the correct order.

-Roy

On Sep 13, 2010, at 6:50 AM, stephen.pascoe@xxxxxxxxxx wrote:

> Thanks Cedric and Mario,
> 
> Apart from demonstrating that my C/C++ is a bit rusty ;-), I think there is a 
> take-home message here.  Linking code against NetCDF has got a lot more 
> complex with NetCDF4.  The excellent documentation would be further improved 
> with tips on compiling and linking.
> 
> If this can be done I'd also recommend pointing out the usefulness of -fPIC.
> I often find NetCDF libraries are installed statically without 
> position-independent code.  This makes them unsuitable for wrapping inside 
> dynamic libraries used in dynamic language bindings: e.g. CDAT and 
> netcdf4-python
> 
> Thanks,
> Stephen.
> 
> ---
> Stephen Pascoe  +44 (0)1235 445980
> British Atmospheric Data Centre
> Rutherford Appleton Laboratory
> 
> -----Original Message-----
> From: Cedric Roux [mailto:cedric.roux@xxxxxxxxxx] 
> Sent: 13 September 2010 14:35
> To: Pascoe, Stephen (STFC,RAL,SSTD)
> Cc: netcdfgroup@xxxxxxxxxxxxxxxx
> Subject: Re: [netcdfgroup] Linker option ordering when linking to HDF5
> 
> stephen.pascoe@xxxxxxxxxx wrote:
>> I've noticed that when building statically linked executables the 
>> order of the link options is important.  For instance:
>> 
>> $ g++ -static -L... -I... foo.c -lnetcdf -lhdf5 -lhdf5_hl -lm -lz -o 
>> foo
>> /usr/local/lib/libhdf5_hl.a(H5LT.o): In function `H5LT_dtype_to_text':
>> H5LT.c:(.text+0x26e4): undefined reference to `H5Tget_cset'
>> H5LT.c:(.text+0x290b): undefined reference to `H5Tset_cset'
>> H5LT.c:(.text+0x2a55): undefined reference to `H5Tset_cset'
>> H5LT.c:(.text+0x2c4f): undefined reference to `H5Tget_tag'
>> /usr/local/QC/lib/libhdf5_hl.a(H5LTparse.o): In function `H5LTyyparse':
>> H5LTparse.c:(.text+0xe85): undefined reference to `H5Tset_tag'
>> H5LTparse.c:(.text+0x1077): undefined reference to `H5Tset_cset'
>> collect2: ld returned 1 exit status
>> 
>> However this works:
>> $ g++ -static -L... -I... foo.c -lnetcdf -lhdf5_hl -lhdf5 -lm -lz -o 
>> foo
> 
> g++ -static -L... -I... foo.c -Wl,--start-group -lnetcdf -lhdf5 
> g++ -lhdf5_hl -lm -lz -Wl,--end-group -o foo
> may work too (not tested). See the manpage of 'ld'.
> --start-group/--end-group is what you're after.
> Hope that helps.
> Cédric
> -- 
> Scanned by iCritical.
> 
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit: 
> http://www.unidata.ucar.edu/mailing_lists/ 

**********************
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn@xxxxxxxx (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 



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