程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败?

开发过程中遇到通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败的问题如何解决?下面主要结合日常开发的经验,给出你关于通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败的解决方法建议,希望对你解决通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败有所启发或帮助;

我已经通过 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

我该怎么做才能解决这个问题?感谢您的任何投入!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败全部内容,希望文章能够帮你解决通过 MacPorts 在 MacOS 上安装 C++ NetCDF4 库失败所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。