Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Compiling C++ code with NetCDF libraries: "undefined reference"


    I am trying to compile a C++ code with cmake and gcc on Ubuntu. The code uses NetCDF4 libraries. I specify the path to these libraries as follows:

    -I/usr/local/include -L/usr/local/lib -lnetcdf -lnetcdf_c++4
    "ccmake" and "cmake" work fine. After typing "make" I receive the error message:

    Linking CXX executable guess
    CMakeFiles/guess.dir/modules/guessio_daily_netCDF.cpp.o: In function `getYearlyRecord(Coord, double*, xtring, int)':
    guessio_daily_netCDF.cpp:(.text+0x8309): undefined reference to `netCDF::NcFile::NcFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, netCDF::NcFile::FileMode)'
    I receive the same message when I specify the path to my NetCDF4 libraries with a not-existing path (e.g. -I/blablabla/include ...). As I understand, the linker does not find my NetCDF libraries, correct? Do you have any suggestions on how to solve this problem? Incase it helps, below I include the paths of all my netcdf libraries. The libraries were built with the same compiler (gcc). Thank you very much in advance!


    Last edited by MikeTbob; 09-21-2012 at 10:05 PM. Reason: added code tags

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    How did you install netCDF? If via the system package manager, then they are probably in /usr/include, not /usr/local/include. Also, did you install the development package, or just the libraries themselves? You need the development package which would include the headers.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Hi Rubberman!
    Thanks for your reply! I built my libraries from source. First I install '"zlib", then "HDF5" and finally "netcdf-4.0.tar.gz" with NetCDF4 enabled:

    ./configure --enable-netcdf-4 --with-zlib=/usr/local/zlib --with-hdf5=/usr/lib/

    As far as I know "netcdf-4.0.tar.gz" is the development package, correct?

    Finally, I install "netcdf-cxx4-4.2.tar.gz".

    "/usr/local/include" contains:
    ncarg ncCheck.h ncEnumType.h ncGroupAtt.h ncOpaqueType.h ncUbyte.h ncvalues.h netcdf
    ncAtt.h ncCompoundType.h ncException.h ncGroup.h ncShort.h ncUint64.h ncVarAtt.h netcdfcpp.h netcdf.mod
    ncByte.h ncDim.h ncFile.h ncInt64.h ncString.h ncUint.h ncVar.h netcdf.h typesizes.mod
    ncChar.h ncDouble.h ncFloat.h ncInt.h ncType.h ncUshort.h ncVlenType.h netcdf.hh

    And "/usr/local/lib" contains:
    libblas_ncl.a liblapack_ncl.a libncarg_ras.a libnetcdf_c++4.a libnfp.a libsphere3.1_dp.a R
    libcgm.a libncarg.a libncl.a libnetcdf_c++.a libnfpfort.a ncarg
    libfftpack5_dp.a libncarg_c.a libnclapi.a libngmath.a pkgconfig
    libhlu.a libncarg_gks.a libnetcdf.a libnio.a python2.7

    So "-I/usr/local/include -L/usr/local/lib" should be correct. In case you have any other ideas, please let me know. Thank you ver much!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts