c++ - Linking and using netCDF with gcc -
im trying use netcdf library in c++ project, cannot, reason, use it.
here make file
netcdf = -l/usr/lib -lnetcdf_c++ wilxapp = -lsrc src/wilxtest.cpp -o bin/debug/wilxastaktest debug: g++ -wall -ggdb $(netcdf) $(wilxapp)
in cpp file have (removed bloat)
#include <iostream> #include <netcdfcpp.h> int main(int argc, char* argv[]) { ncfile datafile("simple_xy.nc", ncfile::replace); }
and this:
undefined reference `ncfile::ncfile(char const*, ncfile::filemode, unsigned long*, unsigned long, ncfile::fileformat)'|
i'm not sure errors you're providing match source you're showing, since undefined reference constructor signature has no relationship way you've invoked constructor in example.
anyway, suspect problem order matters on link line. linker walks through libraries etc. 1 time, if comes later on link line needs comes earlier on link line, fail. must order link line such things require other things come first, , things required come later.
a few other tips: -l
option gives search paths libraries, don't need -lsrc
here there's no library you're linking src
directory. don't need add -l/usr/lib
(in fact, it's bad idea) compiler searches system directories in proper order, , on many systems (that support multiple architectures example) /usr/lib
won't right place.
finally, when writing makefiles remember recipe should create exact filename of target: gnu make can use $@
in cases. , need use source file prerequisite, otherwise might not bother using make , write shell script. try this:
netcdf = -lnetcdf_c++ wilxapp = src/wilxtest.cpp cxx = g++ cxxflags = -wall -ggdb bin/debug/wilxastaktest: $(wilxapp) $(cxx) $(cxxflags) -o $@ $^ $(netcdf)
Comments
Post a Comment