This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: Glen Kaukola <address@hidden> >Organization: UCR >Keywords: 200405111925.i4BJPZtK000957 netCDF link Glen, >I'm having trouble getting a simple C program to link. Right now, I'm >only calling two NetCDF functions, nc_open and nc_close, but the linker >always tells gives me an undefined reference error for both of those >functions. > >The link command I'm running looks exactly like this: >gcc -L/home/aqm/glen/Projects/netcdf-3.5.1/src/libsrc -lnetcdf >test_ncf.o -o test_ncf.x Assuming that you have a valid netCDF library in the directory: /home/aqm/glen/Projects/netcdf-3.5.1/src/libsrc your gcc command line should be OK. Given this, the first things I would check are: - you have a file libnetcdf.a in the /home/aqm/glen/Projects/netcdf-3.5.1/src/libsrc directory - the library is non-zero in length - the library was built on the system you are trying to use it on After doing the above, you can use the 'nm' command to list out the entry points in libnetcdf.a to make sure that it has the nc_open and nc_close routines you need: nm libnetcdf.a | grep nc_open >Also, we've just upgraded all our systems to Fedora Core 1, so maybe >that has something to do with it? If you did not rebuild your netCDF library after the upgrade, it may be part of the problem. There is no problem using netCDF 3.5.1 under Fedora Core 1; we use it routinely here at the UPC. >Any insight into this problem would be greatly appriciated. If you did not rebuild libnetcdf.a, please do so and retry your link. >Thanks, No worries. Cheers, Tom Yoksas -- NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publically available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us. >From address@hidden Wed May 12 16:15:07 2004 Actually, I figured out what the problem is. If my link step is set up like this then it doesn't work: gcc -L/home/aqm/glen/Projects/netcdf-3.5.1/src/libsrc -lnetcdf test_ncf.o -o test_ncf.x But if I change it around so it looks like this, then it works: gcc test_ncf.o -o test_ncf.x -L/home/aqm/glen/Projects/netcdf-3.5.1/src/libsrc -lnetcdf It seems my thinking about how linkers work was all backwards. It needs to find symbols in the object file first so it doesn't first scan through a library and determine that there's nothing in the library it needs. At least that's how I understand it. Glen