views:

669

answers:

4

Greetings Everyone,

Trying to compile using g++ and need to link the standard f90 (or f77 even) libraries for some fortran source codes in my Makefile. I cant find the name of it anywhere.

Makerfile:

products: SlowDynamic.exe

SlowDynamic.exe: main.o SA.o mersenne.o CFE.o BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o MA_57.o blas.o MA_57_Depend.o Metis.o
    g++ -L/usr/sfw/lib -R/usr/sfw/lib -lgcc_s -lstdc++ -o SlowDynamic.exe main.o \
     SA.o mersenne.o CFE.o MA_57.o blas.o MA_57_Depend.o Metis.o\
     BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o

main.o: main.cpp
    g++ -c -o main.o main.cpp

SA.o: SA.cpp
    g++ -c -o SA.o SA.cpp

mersenne.o: mersenne.cpp
    g++ -c -o mersenne.o mersenne.cpp

CFE.o: CFE.c
    gcc -c -o CFE.o CFE.c

MA_57.o: MA_57.f
    f77 -c -o MA_57.o MA_57.f

blas.o: blas.f
    f77 -c -o blas.o blas.f

MA_57_Depend.o: MA_57_Depend.f
    f77 -c -o MA_57_Depend.o MA_57_Depend.f

Metis.o: Metis.f
    f77 -c -o Metis.o Metis.f

BCs.o: BCs.c
    gcc -c -o BCs.o BCs.c

EMatrix.o: EMatrix.c
    gcc -c -o EMatrix.o EMatrix.c

Numbering.o: Numbering.c
    gcc -c -o Numbering.o Numbering.c

KMatrix.o: KMatrix.c
    gcc -c -o KMatrix.o KMatrix.c

Solve.o : Solve.c
    gcc -c -o Solve.o Solve.c

clean: 
    rm *.o Main.exe *.gpi

Compiler:

birch $ make
mksh: Warning: newline is not last character in file Makefile
Current working directory /u/f/osv20/Y4-UNIX/complete
g++ -L/usr/sfw/lib -R/usr/sfw/lib -lgcc_s -o SlowDynamic.exe main.o \
        SA.o mersenne.o CFE.o MA_57.o blas.o MA_57_Depend.o Metis.o\
        BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o
Undefined                       first referenced
 symbol                             in file
__f90_sfw_i4                        MA_57.o
__f90_sfw_ch                        MA_57.o
__f90_sfw_r4                        MA_57.o
__f90_ifw_ch                        MA_57.o
__f90_ifw_r4                        MA_57.o
__nintf                             MA_57.o
__s_cmp                             blas.o
__r_sign                            MA_57_Depend.o
__f90_sifw                          MA_57.o
__f90_ssfw                          MA_57.o
__f90_stop                          blas.o
__f90_esfw                          MA_57.o
__f90_eifw                          MA_57.o
ld: fatal: Symbol referencing errors. No output written to SlowDynamic.exe
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `SlowDynamic.exe'

Results for running 'f77 -v hello.f'

amos $ f77 -v hello.f
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -v hello.f
###     command line files and options (expanded):
### -f77=%all -ftrap=%none -v hello.f -lf77compat
### f90: Note: NLSPATH = /opt/SUNWspro/prod/bin/../lib/locale/%L/LC_MESSAGES/%N.cat:/opt/SUNWspro/prod/bin/../../lib/locale/%L/LC_MESSAGES/%N.cat
/opt/SUNWspro/prod/bin/f90comp -y-o -yhello.o -ev -y-ftrap=%none -m3 -dq -y-fbe -y/opt/SUNWspro/prod/bin/fbe -y-xarch=generic -y-s -H "/opt/SUNWspro/prod/bin/f90 -f77 -ftrap=%none -v " -y-xcache=generic -xcache=generic -I/opt/SUNWspro/prod/include/f95/v8 -p/opt/SUNWspro/prod/lib/modules -y-verbose -xall -xmemalign=8i -y-xmemalign=8i -f77=%all -y-xdbggen=no%stabs+dwarf2 -y-xdbggen=incl -xassume_control=optimize -y-xassume_control=optimize -iorounding=processor-defined -xhasc=yes hello.f
hello.f:
 MAIN hellow:
### f90: Note: LD_LIBRARY_PATH = (null)
### f90: Note: LD_RUN_PATH     = (null)
### f90: Note: LD_OPTIONS = (null)
/usr/ccs/bin/ld -t -R/opt/SUNWspro/lib/sparc:/opt/SUNWspro/lib -o a.out /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xi.o -Y P,/opt/SUNWspro/lib/sparc:/opt/SUNWspro/prod/lib/sparc:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib hello.o -lf77compat -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -Bdynamic -lmtsk -lm -lc /opt/SUNWspro/prod/lib/crtn.o
rm hello.o

Results for running 'f90 -v hello.f'

amos $ f90 -v hello.f
###     command line files and options (expanded):
### -v hello.f
### f90: Note: NLSPATH = /opt/SUNWspro/prod/bin/../lib/locale/%L/LC_MESSAGES/%N.cat:/opt/SUNWspro/prod/bin/../../lib/locale/%L/LC_MESSAGES/%N.cat
/opt/SUNWspro/prod/bin/f90comp -y-o -yhello.o -ev -y-ftrap=common -m3 -dq -y-fbe -y/opt/SUNWspro/prod/bin/fbe -y-xarch=generic -y-s -H "/opt/SUNWspro/prod/bin/f90 -v " -y-xcache=generic -xcache=generic -I/opt/SUNWspro/prod/include/f95/v8 -p/opt/SUNWspro/prod/lib/modules -y-verbose -xall -xmemalign=8i -y-xmemalign=8i -y-xdbggen=no%stabs+dwarf2 -y-xdbggen=incl -xassume_control=optimize -y-xassume_control=optimize -iorounding=processor-defined -xhasc=yes hello.f
### f90: Note: LD_LIBRARY_PATH = (null)
### f90: Note: LD_RUN_PATH     = (null)
### f90: Note: LD_OPTIONS = (null)
/usr/ccs/bin/ld -t -R/opt/SUNWspro/lib/sparc:/opt/SUNWspro/lib -o a.out /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/misalign.o /opt/SUNWspro/prod/lib/values-xi.o -Y P,/opt/SUNWspro/lib/sparc:/opt/SUNWspro/prod/lib/sparc:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib hello.o -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -Bdynamic -lmtsk -lm -lc /opt/SUNWspro/prod/lib/crtn.o
rm hello.o

Results for a successful compile using f77:

amos $ make
mksh: Warning: newline is not last character in file Makefile
Current working directory /u/f/osv20/Y4-UNIX/complete
g++ -c -o main.o main.cpp
In file included from main.cpp:16:
SA.h:85:9: warning: no newline at end of file
main.cpp:38:2: warning: no newline at end of file
g++ -c -o SA.o SA.cpp
In file included from SA.cpp:22:
SA.h:85:9: warning: no newline at end of file
In file included from SA.cpp:23:
CFE.h:25:8: warning: no newline at end of file
SA.cpp:468:4: warning: no newline at end of file
g++ -c -o mersenne.o mersenne.cpp
gcc -c -o CFE.o CFE.c
In file included from BCs.h:9,
                 from CFE.c:29:
fg_types.h:38:7: warning: no newline at end of file
In file included from CFE.c:29:
BCs.h:15:84: warning: no newline at end of file
In file included from CFE.c:32:
KMatrix.h:12:171: warning: no newline at end of file
In file included from CFE.c:34:
Solve.h:9:91: warning: no newline at end of file
CFE.c: In function `CFE':
CFE.c:145: warning: `return' with a value, in function returning void
gcc -c -o BCs.o BCs.c
In file included from BCs.h:9,
                 from BCs.c:9:
fg_types.h:38:7: warning: no newline at end of file
In file included from BCs.c:9:
BCs.h:15:84: warning: no newline at end of file
BCs.c:74:2: warning: no newline at end of file
gcc -c -o EMatrix.o EMatrix.c
In file included from EMatrix.h:9,
                 from EMatrix.c:9:
fg_types.h:38:7: warning: no newline at end of file
EMatrix.c:78:2: warning: no newline at end of file
gcc -c -o Numbering.o Numbering.c
In file included from Numbering.h:8,
                 from Numbering.c:8:
fg_types.h:38:7: warning: no newline at end of file
Numbering.c:144:3: warning: no newline at end of file
gcc -c -o KMatrix.o KMatrix.c
In file included from KMatrix.h:8,
                 from KMatrix.c:9:
fg_types.h:38:7: warning: no newline at end of file
In file included from KMatrix.c:9:
KMatrix.h:12:171: warning: no newline at end of file
KMatrix.c:194:2: warning: no newline at end of file
gcc -c -o Solve.o Solve.c
In file included from Solve.c:8:
Solve.h:9:91: warning: no newline at end of file
Solve.c:95:2: warning: no newline at end of file
f77 -c -o MA_57.o MA_57.f
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -c -o MA_57.o MA_57.f
MA_57.f:
        ma57i:
        ma57a:
        ma57b:
        ma57c:
        ma57q:
        ma57r:
        ma57u:
        ma57s:
        ma57t:
        ma57d:
        ma57e:
        ma57g:
        ma57j:
        ma57k:
        ma57f:
        ma57l:
        ma57m:
        ma57n:
        ma57o:
        ma57p:
        ma57w:
        ma57x:
        ma57y:
        ma57v:
        ma57h:
        ma57z:
f77 -c -o blas.o blas.f
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -c -o blas.o blas.f
blas.f:
        sgemm:
        stpsv:
        isamax:
        xerbla:
        lsame:
        sgemv:
f77 -c -o MA_57_Depend.o MA_57_Depend.f
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -c -o MA_57_Depend.o MA_57_Depend.f
MA_57_Depend.f:
        mc47a:
        mc47b:
        mc71a:
        mc34a:
        mc59a:
        mc59b:
        mc59c:
        mc59d:
        mc59e:
        mc59f:
        ma27i:
        ma27a:
        ma27b:
        ma27c:
        ma27g:
        ma27h:
        ma27u:
        ma27j:
        ma27k:
        ma27l:
        ma27m:
        ma27n:
        ma27o:
        ma27p:
        ma27q:
        ma27r:
        mc64i:
        mc64a:
        mc64b:
        mc64d:
        mc64e:
        mc64f:
        mc64r:
        mc64s:
        mc64q:
        mc64u:
        mc64w:
        mc21a:
        mc21b:
        fd15a:
f77 -c -o Metis.o Metis.f
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -c -o Metis.o Metis.f
Metis.f:
        metis_nodend:
f77 -L/usr/sfw/lib -R/usr/sfw/lib -lgcc_s -lstdc++ -o SlowDynamic.exe main.o \
        SA.o mersenne.o CFE.o MA_57.o blas.o MA_57_Depend.o Metis.o\
        BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o
NOTICE: Invoking /usr/bin/f90 -f77 -ftrap=%none -L/usr/sfw/lib -R/usr/sfw/lib -lgcc_s -lstdc++ -o SlowDynamic.exe main.o SA.o mersenne.o CFE.o MA_57.o blas.o MA_57_Depend.o Metis.o BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o
A: 

Fortran doesn't have "standard libraries". It does have a lot of intrinsic functions, but they are part of the language, defined by the standard.


Answers to comments, since the comment field is a little too restrictive in regard to number of characters:

@Michael - Yes, you can say that. But, still, it is not the same as with other languages you are probably accustomed to. What I mean is this; when you compile and build a fortran program the compiler or linker does not require you to include libraries in the process. It is the compiler's internal thing. This goes for "standard" functions (intrinsics and such).

If you're using some outer functions or subroutines (for example, some plotting routines) then you need to include them separately.

But if you're using standard mathematical functions which are part of the language, then your job is finished. You write your program, and compile and build it. No need to know where or how those functions are implemented, where there implementations are stored and such. That's the compiler's job.

ldigas
But surely when the GNU Compiler Collection is building a FORTRAN program it needs to link in some sort of support library?
Michael Burr
Added the exact code. you can see which files are fortran in the Makefile and as the undefined references in the compiler feedback
Raugnar
@Raugnar - I must admit, since I don't use makefiles, the given listing is a little confusing to me. I see a lot of .f files, and some .o files (object ?), but I cannot tell what is missing from that. Please elaborate if you can.
ldigas
Technically you're correct, but the problem here it that his main program is C++ and obviously the C++ compiler is unaware how to link in the relevant Fortran runtime libraries.
janneb
+2  A: 

What version of GCC are you using? The fortran compiler in GCC has changed completely over time (g77 vs gfortran) - so the correct answer is very dependent on exact versions. It's been a while since I needed to do this (and I used old g77 versions - so things may have changed) but I recall a couple of options at the time were:

  • Try link using g77 and include library -lstdc++ (and possibly -lm?)
  • Try link using g++ and include libraries -lg2c -lm (and possibly -lfrtbegin?)

If using newer gfortran then -lgfortran should work if linking with g++ and -lstdc++ if linking with gfortran.

You also want to make sure that the g++ and f77 commands in your makefile are running the commands that you expect them to be running (e.g. not accessing executables in unexpected directories or different/incompatible versions).

EDIT: From your recent edits to your question you appear to be trying to link the SUN compiler's f77 with the GCC g++. I don't think this is possible. Try using GCC's g77 or gfortran instead of SUN f77.

luapyad
Raugnar
See my edits to answer - you may be using the SUN fortran compiler and not the GCC fortran compiler. In GCC 3.4.3 you should have g77. (GCC >= 4 has new gfortran).
luapyad
+2  A: 

Raugnar,

I refer you to my answer to your previous question about unresolved symbols.

Just run:

f77 -v something.f

on a standalone Fortran90 program and the compiler will reveal exactly which support libraries are linked in by default.

Alnitak
Done that and tested every single one of them, with none listed that work and solve the poroblem. The reason for switching from compiling via f77 to g++ is so that I can get the symbols in for debugging to sort out my previous question.
Raugnar
A: 

Finally fixed the solution with a mix of everyones advice.

Once I realised I was using SUN rather than GCC I switched to compiling with cc (gcc), CC (g++) and f95 (f77).

What solved the problem was pasting in the entire linker line from f77 verbose feedback (above in main post) and gradually deleting those parts that didn't contribute. In the end the following text was added:

-t -R/opt/SUNWspro/lib/sparc:/opt/SUNWspro/lib -Y P,/opt/SUNWspro/lib/sparc:/opt/SUNWspro/prod/lib/sparc:/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib -lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfsu -lsunmath -Bdynamic -lmtsk -lm -lc

Raugnar