I need to use MRQMIN subroutine in my Fortran 90 code. Inside this subroutine there are some other modules nrtype.90, nrutil.f90 and nr.f90. I'm compiling all these modules and my own code with these commands
ifort -c nrtype.90
ifort -c nrutil.f90
ifort -c nr.f90
ifort test.f90 nrtype.o nrutil.o nr.o -o test
but I'm receiving this error
/tmp/ifortcx4Tb3.o: In function `mrqmin_IP_mrqmin_private_':
test.f90:(.text+0x4041): undefined reference to `gaussj_'
test.f90:(.text+0x4896): undefined reference to `covsrt_'
test.f90:(.text+0x48a5): undefined reference to `covsrt_'
am I missing some thing here during the compilation?
nr.f90 only provides the interfaces to the subroutines, not the subroutines themselves.
You have to compile gaussj.f90 and covsrt.f90 separately and specify them as well (I tried it for gfortran but it should work with ifort as well):
gfortran -c gaussj.f90
gfortran -c covsrt.f90
gfortran test.f90 mrqmin.o nr.o nrtype.o nrutil.o gaussj.o covsrt.o
Related
I would like to write a Fortran code that could use MPI if it is compiled by mpif90 but that could also run if it is compiled with gfortran (only, without MPI lib).
So I though using a preprocessing condition, but looking on the Internet I found nothing about such preprocessing variable defined by MPI.
For example, I would like to compile this trivial code test.f90:
Program Main
#ifdef __MPI
USE MPI
#endif
implicite none
integer Ierror
#ifdef __MPI
call MPI_INTI(Ierror)
write (*,*) 'MPI detected'
#else
write (*,*) 'MPI not detected'
#endif
End
Then, if I compile the previous Non-working example with mpif90 I shoud get
$ mpif90 -cpp -o prog test.f90 && prog
> MPI detected
while if I compile with gfortran, I should get
$ gfortran -cpp -o prog test.f90 && prog
> MPI not detected
So is there a preprocessing condition (or another way) that could make this kind of example working ?
I am running the following command to compile a Fortran code
gfortran -ffree-form -ffree-line-length-0 -ff2c -fno-second-underscore -I/opt/fftw-3.3.5/include -O3 -c xml.f90 -I/opt/openmpi-2.0.1/include -pthread -I/opt/openmpi-2.0.1/lib
xml.F:641.46:
CALL XML_TAG("set", comment="spin "
1
Error: Syntax error in argument list at (1)
That line is
CALL XML_TAG("set", comment="spin "//TRIM(ADJUSTL(strcounter)))
It seems that the code is compatible Fortran. I don't know which version, but currently, gfortran is 4.9.2 (ubuntu 15.04). How can I fix that?
Using ubuntu 14.04 octave 3.8.1.
I'm attempting to create an .oct file which makes use of multithreaded fortran program. However, mkoctfile fails to use the related libraries during linking.
The files I'm using look as follows:
c:
#include <octave/oct.h>
extern "C" {
void fort5();
}
DEFUN_DLD (ce5, args, ,"help here")
{
fort5();
}
fortran:
subroutine fort5() bind(c)
use iso_c_binding
implicit none
!$OMP PARALLEL
write(*,*) "Hello"
!$OMP END PARALLEL
end subroutine fort5
I expect this code to result in output of four lines of "Hello".
I compile it with following command
mkoctfile CPP.cpp FORTRAN.f90
As a result I get only one output line, which indicates multitrhreading was ignored.
When compiled outside octave (with minor alterations to c++ file) with following command:
gcc -c CPP.cpp && gfortran -Wall -fimplicit-none -Wtabs -fdefault -real-8 -fopenmp -c FORTRAN.f90 &&gfortran -fopenmp -o3 CPP.o FORTRAN.o -lstdc++ -o OUT.out
The result is as it should be.
From several tests it becomes apparent, that mkoctfile is not capable to use -fopenmp flag in any form. As found on the internet this should be solvable by using LDFLAGS, however, for some reason I fail at that.
I set the enviroment variable in octave terminal with
setenv("LDFLAGS","-Wl,-Bsymbolic-functions, -Wl,-z,relro, -fopenmp")
setenv("FFLAGS","-g -O2 -fstack-protector --param=ssp-buffer-size=4 -fopenmp")
the $mkoctfile --print LDFLAGS indicates that the variable was set successfully. However, the compiled function fails to load: $undefined symbol: GOMP_parallel_start
I've tried explicitly listing the library but the result was the same.
mkoctfile ce5.cpp fort5.o '-Wl,-fopenmp' '-l /usr/lib/x86_64-linux-gnu/libgomp.so.1
mkoctfile ce5.cpp fort5.o '-Wl,-fopenmp' '-L /usr/lib/x86_64-linux-gnu/'
Did I use the flags correctly? What else should I do to get correct compilation?
Problem solved:
Seems like consecutive application of the following commands done the trick:
setenv("FFLAGS","-g -O2 -fstack-protector --param=ssp-buffer-size=4 -fopenmp")
setenv("LDFLAGS","-Wl,-Bsymbolic-functions, -Wl,-z,relro, -Wl,-fopenmp")
mkoctfile ce5.cpp fort5.o '-L, /usr/lib/x86_64-linux-gnu/libgomp.so.1'
Most likely the problem was setting correct flag for compiler ($-fopenmp in FFLAGS) and correct indication of library location.
I am trying to compile a valid Fortran 77 file using the gfortran compiler. I use the following command to compile the Fortran:
gfortran -c main.f -o main-fortran.o -llapack -lblas
I also need to link this with a C++ program, which is compiled, like so:
g++ -c main.cpp -o main-cpp.o
Both of these files compile without any errors or warnings.
However, I cannot link them together into an executable. Here is the command I am using:
g++ main-cpp.o main-fortran.o -o run.exe -lgfortran -llapack -lblas
The linker then gives this error:
main-fortran.o: In function `main':
main.f:(.text+0x2e18): multiple definition of `main'
main-cpp.o:main.cpp:(.text+0x8e9): first defined here
collect2: ld returned 1 exit status
You can find the source files here: C++ and Fortran 77.
Any idea what I can do to overcome this?
You have two main programs: one in C++ and one in Fortran. Delete the Fortran one either by
Option 1:
The first bit of your Fortran program should be a BLOCK DATA segment. Just add
BLOCK DATA INFO
At the start.
Option 2:
Delete everything up to the first END.
Say I have two files file_1.f90 and file_2.f90 and they use some libraries. Could be any programming language. Then I compile and link in one step using
ifort -I/include_dir_loc -o my.o file_1.f90 file_2.f90 -L/Lib_dir_loc
Is there a way to tell the terminal or ifort or whoever takes over to tell me the individual steps it carries out. It could be that it goes
ifort -I/include_dir_loc -c -o file_1.f90
ifort -I/include_dir_loc -c -o file_2.f90
ifort -o my.o file_1.o file_2.o -L/Lib_dir_loc
What actually happens after I type the first command? Who carries out the compilation using what commands and who coordinates between the compiler and the linker?
for ifort:
-v will show the tool commands and execute them
-dryrun will show the tool commands but will not execute