[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #BJR-880663]: Linking to cpp NetCDF4 on MacOS fails with ld: symbol(s) not found for architecture x86_64


It looks like the issue might be how the file was built via macports.  Is it 
possible to tell macports to install packages from source? This would cause the 
C++ interface to be built with the tools you are using on your MBP, which could 
potentially resolve the inconsistencies being observed between the runtime that 
the binary was built against, versus the compiler and runtime you are using 


> Full Name: Christian Steger
> Email Address: address@hidden
> Organization: ETH Zurich
> Package Version: 4.3.0
> Operating System: macOS Catalina
> Hardware: Macbook Pro (Retina, Mid2012)
> Description of problem: Dear support-team,
> I installed netcdf-cxx4 via MacPorts to use it for a small C++ project. I 
> tried to compile and link the example file 
> (https://www.unidata.ucar.edu/software/netcdf/examples/programs/SimpleXyWr.cpp)
>  with the following command:
> g++ SimpleXyWr.cpp -o SimpleXyWr.out -I/opt/local/include -L/opt/local/lib 
> -lnetcdf -lnetcdf_c++4
> However, this results in the following error:
> Undefined symbols for architecture x86_64:
> "__ZN6netCDF6NcFileC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS0_8FileModeE",
>  referenced from:
> _main in cco9p4yv.o
> "__ZNK6netCDF7NcGroup6addDimERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm",
>  referenced from:
> _main in cco9p4yv.o
> "__ZNK6netCDF7NcGroup6addVarERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_6NcTypeERKSt6vectorINS_5NcDimESaISD_EE",
>  referenced from:
> _main in cco9p4yv.o
> ld: symbol(s) not found for architecture x86_64
> collect2: error: ld returned 1 exit status
> I also posted this question on stackoverflow (with an improved formatting):
> https://stackoverflow.com/questions/68066022/linking-to-c-netcdf4-on-macos-fails-with-ld-symbols-not-found-for-architect
> Am I not using the correct flags for compilation? I also installed the older 
> legacy NetCDF C++ interface - could this somehow cause an interference? 
> Thanks a lot for your help.

Ticket Details
Ticket ID: BJR-880663
Department: Support netCDF
Priority: High
Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly 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.