linking c/c++ code against fortran libraries

Mark Moll mmoll at
Sat May 31 09:44:52 PDT 2008

On May 31, 2008, at 8:21 AM, Takeshi Enomoto wrote:

> Hi,
>> However, to properly link against libfoo.a I also need to
>> include "-lgfortran".
> With a fortran compiler, necessary libraries will be linked.

Yes, but I can't specify in a Portfile two compilers (one for  
compiling c/c++ code, and one for linking the object files). Below is  
how I currently attempt to get around this problem in the arpack  
variant of the slepc port. Arpack is a port for a Fortran library,  
slepc is a port for a C++ library. I am open to suggestions for  

variant arpack description {compile with ARPACK support} {
    pre-fetch {
        if {![file exists ${prefix}/lib/libparpack.a]} {
            return -code error "Please install the mpi variant of  
arpack first."
    # This is a rather fragile way to figure out where the fortran  
library can be
    # found that is needed to link against libparpack.a:
    if {[file exists ${prefix}/lib/gcc43]} {
        set fortrandir ${prefix}/lib/gcc43
    } else {
        if {[file exists ${prefix}/lib/gcc42]} {
            set fortrandir ${prefix}/lib/gcc42
        } else {
            if {[file exists ${prefix}/lib/g95]} {
                set fortrandir ${prefix}/lib/gcc95
            } else {
                return -code error "Please install a fortran compiler  
by installing one of the following ports: gcc42, gcc43, or g95."
    depends_lib-append      port:arpack
    configure.args-append   --with-arpack-dir=${fortrandir} \



More information about the macports-dev mailing list