g95 and G++

Discussion in 'Mac Programming' started by enricoc, Oct 13, 2006.

  1. enricoc macrumors newbie

    Joined:
    Oct 5, 2006
    #1
    Good morning, I have the following problem while interfacing g95 programs with g++:

    fortran file: fortran_file.f

    subroutine prova(var)
    real var
    write(*,*) var
    end

    g95 -c -fno-underscoring fortran_file.f

    c++ main file: main.cxx
    include <iostream>
    using namespace std;
    extern "C"{
    void prova(float*);
    }

    main(){
    float a = 2.;
    prova(&a);
    }

    g++ main.cpp fortran_file.o

    /usr/bin/ld: Undefined symbols:
    __g95_filename
    __g95_ioparm
    __g95_line
    __g95_st_write
    __g95_st_write_done
    __g95_transfer_real
    collect2: ld returned 1 exit status

    Following the suggestions on g95 web site I used the g95_runtime_start function
    void g95_runtime_start(int argc, char *argv[]), but the ld cannot resolve it. Is there one who can give me any suggestions?
     
  2. p96159 macrumors newbie

    Joined:
    Oct 27, 2006
    #2
    You need to include the g95 library when linking. For example on my machine I have to include "-L/sw/lib -lg95" to the gcc/g++ command line.
     

Share This Page