forked from johannesgerer/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex2_gfortran_g++.sh
47 lines (47 loc) · 1.1 KB
/
ex2_gfortran_g++.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#
# Compile the FORTRAN file.
#
# The "fno-underscoring" option keeps the FORTRAN compiler from adding underscores
# to the names of the compiled routines.
#
gfortran -c -fno-underscoring ex2_main.f90 >& compiler.txt
if [ $? -ne 0 ]; then
echo "Errors compiling ex2_main.f90"
exit
fi
rm compiler.txt
#
# Compile the C++ file.
# Every routine in the file that is to be accessed by a FORTRAN routine must be
# declared with the "extern "C" {}" property, so that the C++ compiler doesn't
# do weird things to the names.
#
g++ -c ex2_sub.cpp >& compiler.txt
if [ $? -ne 0 ]; then
echo "Errors compiling ex2_sub.cpp"
exit
fi
rm compiler.txt
#
# Use GFORTRAN to load, but include the libraries that G++ needs.
#
gfortran ex2_main.o ex2_sub.o -lstdc++ -lm
if [ $? -ne 0 ]; then
echo "Errors linking and loading ex2_main.o + ex2_sub.o"
exit
fi
#
mv a.out ex2_gfortran_g++
rm *.o
#
# Run the program.
#
ex2_gfortran_g++ > ex2_gfortran_g++_output.txt
if [ $? -ne 0 ]; then
echo "Errors running ex2_gfortran_g++."
exit
fi
rm ex2_gfortran_g++
#
echo "Program output written to ex2_gfortran_g++_output.txt"