Find the answer to your Linux question:
Results 1 to 3 of 3
Hi! 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: Code: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    8

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


    Hi!

    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:

    Code:
    -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:

    Code:
    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!

    Cheers,
    Chris

    Code:
    /usr/share/man/man3/netcdf.3.gz
    /usr/share/man/man3/netcdf_f77.3.gz
    /usr/share/man/man3/netcdf_f90.3f90.gz
    /usr/share/doc/netcdf-bin
    /usr/share/doc/libnetcdf-dev
    /usr/share/doc/libnetcdf6
    /usr/share/mime/application/x-netcdf.xml
    /usr/lib/libnetcdf_c++.so
    /usr/lib/libnetcdff.so
    /usr/lib/libnetcdf.a
    /usr/lib/netcdf.pc
    /usr/lib/pkgconfig/netcdf.pc
    /usr/lib/libnetcdf.so.6.0.0
    /usr/lib/libnetcdff.so.5.0.0
    /usr/lib/libnetcdf.so.6
    /usr/lib/libnetcdf_c++.so.5
    /usr/lib/libnetcdf.so
    /usr/lib/libnetcdf_c++.a
    /usr/lib/libnetcdff.so.5
    /usr/lib/libnetcdff.a
    /usr/lib/libnetcdf_c++.so.5.0.0
    /usr/include/netcdf.mod
    /usr/include/netcdf.h
    /usr/include/hdf/hdf2netcdf.h
    /usr/include/hdf/hdf4_netcdf.h
    /usr/include/netcdf.hh
    /usr/include/netcdf.inc
    /usr/include/netcdfcpp.h
    /usr/local/lib/libnetcdf_c++4.la
    /usr/local/lib/pkgconfig/netcdf-cxx4.pc
    /usr/local/lib/libnetcdf_c++4.so
    /usr/local/lib/libnetcdf_c++4.so.1.0.2
    /usr/local/lib/libnetcdf_c++4.a
    /usr/local/lib/ncarg/data/cdf/sst30e_netcdf.nc
    /usr/local/lib/ncarg/data/cdf/sstdata_netcdf.nc
    /usr/local/lib/libnetcdf_c++4.so.1
    /usr/local/include/netcdf
    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
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,459
    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
    Just Joined!
    Join Date
    Jun 2010
    Posts
    8
    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 netcdf.inc
    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 libnetcdf_c++4.so.1.0.2 libnfp.a libsphere3.1_dp.a R
    libcgm.a libncarg.a libncl.a libnetcdf_c++4.la libnetcdf_c++.a libnfpfort.a ncarg
    libfftpack5_dp.a libncarg_c.a libnclapi.a libnetcdf_c++4.so libnetcdf_c++.la libngmath.a pkgconfig
    libhlu.a libncarg_gks.a libnetcdf.a libnetcdf_c++4.so.1 libnetcdf.la 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!

    Cheers,
    Chris

Posting Permissions

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