Oli
Oli

Reputation: 1351

How to install gfortran under macports and use it with cmake?

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

Upvotes: 2

Views: 5134

Answers (1)

DLRdave
DLRdave

Reputation: 14250

See the CMake FAQ on how to use a different compiler:

To use gfortran from macports as the fortran compiler, you should:

export FC=/opt/local/bin/gfortran
export CC=/opt/local/bin/gcc
export CXX=/opt/local/bin/g++

...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.

Upvotes: 2

Related Questions