Compiling C/C++/FORTRAN project
Jerry DeLisle
jvdelisle@verizon.net
Sat Oct 25 12:45:00 GMT 2008
sreeram827 wrote:
> Hi all,
>
> My project makes use of C/C++/FORTRAN subroutines. This is how the project
> is structured:
> My main() is in FORTRAN. (say main.f)
> main.f call a set of C subroutines (blah1.c and blah2.c) and
> FORTRAN(prog1.f, prog2.f) subroutines. The C subroutines in turn call the
> C++ subroutines (test1.cpp, test2.cpp)
> Also, these subroutines need to linked to libraries when creating the
> executable.
> So, for compiling the entire project (to create the object files) what I did
> was I used g++ compiler to compile both the C and C++ subroutines and use
> g77 for the FORTRAN codes.
>
> g77 -c *.f
> g++ -c *.c
> g++ -c *.cpp
>
> My question now is when I create the executable, what compiler should I use
> (g77/g++):
> When I try using the g77
> g77 main.f *.o -o exec <libraries>
> I get lot of errors because the libraries dont get linkes
> When I use g++, it says the following
>
> main.o: In function `funcc_':
> main.f:(.text+0x33c): undefined reference to `blah1_'
> main.o: In function `grad_':
> main.f:(.text+0x372): undefined reference to `blah2_'
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libf2c.so: undefined
> reference to `MAIN__'
>
> Can someone get me out of this plz..
>
> Thanks!!
>
>
>
For a start, use gfortran instead of g77. If your main program is written in
Fortran, use gfortran to create the executable.
Jerry
More information about the Fortran
mailing list