g95 and G++

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

  1. enricoc macrumors newbie

    Oct 5, 2006
    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

    g95 -c -fno-underscoring fortran_file.f

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

    float a = 2.;

    g++ main.cpp fortran_file.o

    /usr/bin/ld: Undefined symbols:
    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

    Oct 27, 2006
    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