【发布时间】:2021-09-05 00:18:40
【问题描述】:
我已经通过 Macports 安装了 netcdf-cxx4 并从这里下载了一个 C++ NetCDF4 示例: https://www.unidata.ucar.edu/software/netcdf/examples/programs/SimpleXyWr.cpp
我不太熟悉设置链接选项,我尝试使用以下命令编译/链接程序:
g++ SimpleXyWr.cpp -o SimpleXyWr.out -I/opt/local/include -L/opt/local/lib -lnetcdf -lnetcdf_c++4
但是,这会导致以下错误:
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
我完全不知道如何解决这个问题。
更新:我部分解决了问题:我意识到 MacPorts 使用 clang 来编译端口。因此,我尝试使用以下命令安装 netcdf-cxx4:
sudo port -s -v install netcdf-cxx4 configure.compiler=macports-gcc-10
安装结束:
netcdf-cxx4 is using libstdc++ (this installation is configured to use libc++)
---> Found 1 broken port, determining rebuild order
You can always run 'port rev-upgrade' again to fix errors.
The following ports will be rebuilt: netcdf-cxx4 @4.3.0
Continue? [Y/n]:
如果我输入 Y,netcdf-cxx4 会重新安装(但再次使用 clang - 这对我没有帮助)。如果我中止,我可以使用 NetCDF4 库(一切似乎都正常)。但是,为了解决上述问题,我尝试使用以下命令安装 netcdf-cxx4:
sudo port -s -v install netcdf-cxx4 configure.compiler=macports-gcc-10 configure.cxx_stdlib=macports-libstdc++
但这以错误消息结束:
checking whether the C compiler works... no
configure: error: in `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_gettext/gettext/work/gettext-0.19.8.1/gettext-runtime':
configure: error: C compiler cannot create executables
See `config.log' for more details
configure: error: ./configure failed for gettext-runtime
Command failed: cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_gettext/gettext/work/gettext-0.19.8.1" && ./configure --prefix=/opt/local ac_cv_prog_AWK=/usr/bin/awk ac_cv_path_GREP=/usr/bin/grep ac_cv_path_SED=/usr/bin/sed --disable-csharp --disable-java --disable-native-java --disable-openmp --without-emacs --with-included-gettext --with-included-glib --with-included-libcroco --with-included-libunistring --with-included-libxml --without-cvs --without-git --without-xz
Exit code: 77
Error: Failed to configure gettext, consult /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_gettext/gettext/work/gettext-0.19.8.1/config.log
Error: Failed to configure gettext: configure failure: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_gettext/gettext/main.log for details.
Error: Unable to execute port: upgrade netcdf failed
我能做些什么来解决这个问题?感谢您的任何意见!
【问题讨论】:
-
你能
grep那些缺少符号名称的库吗? -
感谢您的建议。看来我缩小了问题的原因(请参阅上面的更新信息)。
标签: c++ linker-errors macports netcdf4