如何在macports下安装gfortran并与cmake一起使用?
希望有人能帮助我。我需要编译一些代码。我在 /opt/local/ 中安装了 macports 所需的一切。它正在按其应有的方式工作,除了 gFortran 之外。我收到此错误:
ld: library not found for -lgfortran
collect2: ld returned 1 exit status
make[2]: *** [vigranumpy/private/graph/tws/svs.dylib] Error 1
make[1]: *** [vigranumpy/private/graph/tws/CMakeFiles/svs.dir/all] Error 2
make: *** [all] Error 2
我希望将所有内容安装在 /opt/local/ 中,因为我不想触及系统 (/usr/)。 gFortran 不适用于 macport。您可以使用 gcc46 作为变体来安装它。但是如果我使用 gcc46 而不是默认编译器,那么之前的代码需要编译。 我该如何解决这个问题?
亲切的问候
hope someone can me help. I need to compile some code. I installed everything I needed with macports, in /opt/local/. And it's working how it should, except gFortran. I get this error:
ld: library not found for -lgfortran
collect2: ld returned 1 exit status
make[2]: *** [vigranumpy/private/graph/tws/svs.dylib] Error 1
make[1]: *** [vigranumpy/private/graph/tws/CMakeFiles/svs.dir/all] Error 2
make: *** [all] Error 2
I want everything to be installed in /opt/local/, because I don't want to touch the system (/usr/). gFortran isn't available for macports. You can install it with gcc46 as a variant. But if I use the gcc46 instead the default compilers, then the code before want compile.
How can I fix that?
Kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅有关如何使用不同编译器的 CMake 常见问题解答:
要使用 macports 中的 gfortran 作为 fortran 编译器,您应该:
...在调用 CMake 之前。然后,在设置了此类环境变量的情况下调用 CMake 后,它会将编译器路径缓存在 CMakeCache.txt 文件中,因此后续运行时不再需要设置环境变量。
对于混合语言(C、C++、Fortran)项目,编译器之间的良好配合非常重要。
此建议仅适用于“Unix Makefiles”生成器。我不知道有谁通过 Xcode 与 CMake 结合使用 Fortran。
See the CMake FAQ on how to use a different compiler:
To use gfortran from macports as the fortran compiler, you should:
...prior to calling CMake. Then, after calling CMake with such environment variables set, it will cache the compiler paths in the CMakeCache.txt file, so for subsequent runs, you do not need the environment variables set anymore.
For mixed language (C, C++, Fortran) projects, it's important that the compilers all play nicely with each other.
This advice only works with the "Unix Makefiles" generator. I do not know of anybody who is using fortran via Xcode in conjunction with CMake.