I have an extension for matlab that i want to compile. The machine on
which I compile the code has a g77-3.4 and a gfortran-4.2 compiler
installed. If I set the fortran compiler in the Makefile to g77-3.4 the
compilation process runs through without any error messages and I can
use the extension without any problems.
Compilation process with g77-3.4:
toom@gauss:~/Matlab/Mex/lbfgsb-for-matlab> make
/usr/site-local/bin/g77-3.4 -O3 -fPIC -fexceptions -o solver.o -c solver.f
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabexception.o -c matlabexception.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabscalar.o -c matlabscalar.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabstring.o -c matlabstring.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabmatrix.o -c matlabmatrix.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
arrayofmatrices.o -c arrayofmatrices.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o program.o
-c program.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabprogram.o -c matlabprogram.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o lbfgsb.o -c
lbfgsb.cpp
/net/matlab/Matlab2009b/bin/mex -cxx CXX=/usr/site-local/bin/g++-4.2
CC=/usr/site-local/bin/g++-4.2 FC= LD=/usr/site-local/bin/g++-4.2 -lg2c
-lm \
-O -output lbfgsb.mexa64 solver.o matlabexception.o
matlabscalar.o matlabstring.o matlabmatrix.o arrayofmatrices.o program.o
matlabprogram.o lbfgsb.o
toom@gauss:~/Matlab/Mex/lbfgsb-for-matlab>
But when I replace the g77-3.4 with gfortran-4.2 I get a linker error
message that looks like this:
Compilation process with gfortran-4.2:
toom@gauss:~/Matlab/Mex/lbfgsb-for-matlab> make
/usr/site-local/bin/gfortran-4.2 -O3 -fPIC -fexceptions -o solver.o -c
solver.f
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabexception.o -c matlabexception.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabscalar.o -c matlabscalar.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabstring.o -c matlabstring.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabmatrix.o -c matlabmatrix.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
arrayofmatrices.o -c arrayofmatrices.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o program.o
-c program.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o
matlabprogram.o -c matlabprogram.cpp
/usr/site-local/bin/g++-4.2 -O3 -fPIC -pthread -Wall -ansi
-DMATLAB_MEXFILE -I/net/matlab/Matlab2009b/extern/include -o lbfgsb.o -c
lbfgsb.cpp
/net/matlab/Matlab2009b/bin/mex -cxx CXX=/usr/site-local/bin/g++-4.2
CC=/usr/site-local/bin/g++-4.2 FC= LD=/usr/site-local/bin/g++-4.2 -lg2c
-lm \
-O -output lbfgsb.mexa64 solver.o matlabexception.o
matlabscalar.o matlabstring.o matlabmatrix.o arrayofmatrices.o program.o
matlabprogram.o lbfgsb.o
solver.o: In function `timer_':
solver.f:(.text+0x17c4): undefined reference to `_gfortran_etime'
solver.o: In function `dcsrch_':
solver.f:(.text+0x1b66): undefined reference to `_gfortran_compare_string'
solver.f:(.text+0x1ca7): undefined reference to `_gfortran_compare_string'
solver.f:(.text+0x20d8): undefined reference to `_gfortran_compare_string'
solver.f:(.text+0x2215): undefined reference to `_gfortran_compare_string'
solver.o: In function `subsm_':
solver.f:(.text+0x2cce): undefined reference to `_gfortran_st_write'
solver.f:(.text+0x2ce2): undefined reference to
`_gfortran_transfer_character'
solver.f:(.text+0x2cea): undefined reference to `_gfortran_st_write_done'
...
...long list of errors...
...
solver.f:(.text+0xb31c): undefined reference to `_gfortran_st_write'
solver.f:(.text+0xb324): undefined reference to `_gfortran_st_write_done'
solver.o: In function `setulb_':
solver.f:(.text+0xb58c): undefined reference to `_gfortran_compare_string'
collect2: ld returned 1 exit status
mex: link of ' "lbfgsb.mexa64"' failed.
make: *** [lbfgsb.mexa64] Error 1
I'm wondering: Why does this happen? I have another machine on which I
would also like to compile the code but this machine doesn't have g77
installed.