Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab can't not find g95 or gfortran compiler in MEX-Setting

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: J.S.

Date: 7 Jul, 2008 22:01:01

Message: 1 of 10

Hi, everyone,

I have two problems with mex-Setting:

First One:
My Matlab can't find the g95 or gfortran compiler installed on the
computer, say, when I give 'mex -setup', those compilers are not
listed out.
I'm sure that those compilers are there. Can someone tell me, what can
I do to make my Matlab working?
Working environment is: WindowsXP and Matlab7.0

Second One:
On the computer, there're gfortran, g77, but without g95 installed.
When I compile a mex-file in Fortran, Matlab told me, 'g95: Line xx:
command not found'.
Do someone know, what's this problem?
Working environment: LINUX, Matlab7.x

Thx very much!

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Gadi Reinhorn

Date: 9 Jul, 2008 15:59:01

Message: 2 of 10

J.S.

In both your cases the configurations you are trying are not supported.

> First One:
> My Matlab can't find the g95 or gfortran compiler installed on the
> computer, say, when I give 'mex -setup', those compilers are not
> listed out.
> I'm sure that those compilers are there. Can someone tell me, what can
> I do to make my Matlab working?
> Working environment is: WindowsXP and Matlab7.0

Gnu tools are not supported on Windows:
http://www.mathworks.com/support/compilers/1601_70.html


> Second One:
> On the computer, there're gfortran, g77, but without g95 installed.
> When I compile a mex-file in Fortran, Matlab told me, 'g95: Line xx:
> command not found'.
> Do someone know, what's this problem?
> Working environment: LINUX, Matlab7.x

Judging from your observation I assume you are using MATLAB 7.4 or later.
In MATLAB 7.4 (R2007a) we moved from g77 to g95.
http://www.mathworks.com/support/compilers/1601_74.html
http://www.mathworks.com/access/helpdesk/help/techdoc/rn/bq2fbr7-1.html#bq4je4u-1
See the "Discontinued Compiler Support" list and the "New Compiler Support"
list.

Hope that helps.
Gadi

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Kevin Johnson

Date: 27 Nov, 2009 01:00:04

Message: 3 of 10

I am having a similar problem

OS X 10.6.2, XCode 3.2
Matlab 7.9 R2009b 64 bit
GNU gfortran 4.3.0

mex -setup does not find the compiler, even though gfortran 4.3.0 is explicitly listed on the Mathworks site as supported in R2009b:

http://www.mathworks.com/support/compilers/R2009b/maci64.html

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Thomas Clark

Date: 27 Nov, 2009 23:14:04

Message: 4 of 10

Boo hoo.. not supported compilers :(

Never fear! I've never used a supported compiler yet! :)

Here's what I'd do (bear in mind I'm on my windows box at the moment, so can't look up locations of things - sorry):

1. Forget about mex -setup and compile your mex files straight through your compiler and linker. Name the output files so they've got the right extension (.mexglx, if yours is 32 bit linux).

2. You'll need to include and link a number of files in addition to whatever source or library files make up your own code. To find out what these are, find the mexopts files (search in the matlab directory). One of them will be set up for fortran. You can infer what files etc to link (and what locations those files are in) either by combing through that code, or by using the -verbose option when you attempt to compile a mex file the way you've been doing it.

3. I always write a m-file which uses the system() function to issue the compile command to the terminal, that way, I can still compile m files from within MATLAB.

4. The contents of one of my compile functions looks like this:

** health warning, if the formatting gets all messed up, email me at
t.clark at cantab.net
and I'll send you the proper file **

%% COMPILE THE MXMART MEX FILE
% This file contains the system commands used to compile the mxmart mex file
% in Linux / Unix.
%
% Run this script (which should issue the commands directly to the system for
% you). If that doesn't work, Simply open a bash terminal (or equivalent),
% navigate to the directory in which the source code resides, then copy and
% paste the commands below into the terminal in the same order as below.
%
%
% For Windows-based platforms, install Intel Visual Fortran and
% use the default procedures for mex file building highlighted in the MATLAB
% help files.
disp('____________________ COMPILING mxmart_large ________________________')


%% DETERMINE COMPILATION OPTIONS TO USE

invalid = true;
while invalid
    disp('Options:')
    disp('1 Compile mex file for debugging with g95 / gdb')
    disp('2 Compile mex file for debugging with Intel Fortran / gdb')
    disp('3 Compile mex file for optimisation with Intel Vtune / Fortran')
    disp('4 Compile mex file for optimised running with Intel Fortran')
    disp('5 Compile mex file for optimised running with g95')
    user_entry = input('Please enter selection: ');
    if (user_entry == 1) || (user_entry == 2) || (user_entry == 3) || (user_entry == 4) || (user_entry == 5)
        invalid = false;
    end
end

       
%% DEBUGGING - G95 COMPILER

% Use the following commands to compile with g95. You can then debug with the
% gdb debugging program (instructions for debugging MEX files with gdb in unix
% are on the mathworks web site help)

if user_entry == 1
    [status, result] = system('g95 -c -g -I/usr/matlab7.6/extern/include -I/usr/matlab7.6/simulink/include -fexceptions -fPIC -DMX_COMPAT_32 "mxmart_large.F90"');
    disp(result)
    if status == 0
        [status, result] = system('g95 -g -pthread -shared -m32 -Wl,--version-script,/usr/matlab7.6/extern/lib/glnx86/fexport.map -Wl,--no-undefined -o "mxmart_large.mexglx" mxmart_large.o "/usr/matlab7.6/extern/lib/glnx86/version4.o" -Wl,-rpath-link,/usr/matlab7.6/bin/glnx86 -L/usr/matlab7.6/bin/glnx86 -lmx -lmex -lmat -lm -L/usr/g95-x86-linux/g95-install/lib/gcc-lib/i686-suse-linux-gnu/4.0.3 -lf95');
        disp(result)
    end
end


%% DEBUGGING - INTEL FORTRAN COMPILER
if user_entry == 2
    [status, result] = system('ifort -c -g -check all -fpe-all=0 -fp-stack-check -diag-enable warn -traceback -I/usr/matlab7.6/extern/include -I/usr/matlab7.6/simulink/include -fexceptions -fPIC -DMX_COMPAT_32 "mxmart_large.F90"');
    disp(result)
    if status == 0
        [status, result] = system('ifort -g -check all -fpe-all=0 -fp-stack-check -diag-enable warn -traceback -pthread -shared -m32 -Wl,--version-script,/usr/matlab7.6/extern/lib/glnx86/fexport.map -Wl,--no-undefined -o "mxmart_large.mexglx" mxmart_large.o "/usr/matlab7.6/extern/lib/glnx86/version4.o" -Wl,-rpath-link,/usr/matlab7.6/bin/glnx86 -L/usr/matlab7.6/bin/glnx86 -lmx -lmex -lmat -lm -L/usr/g95-x86-linux/g95-install/lib/gcc-lib/i686-suse-linux-gnu/4.0.3 -lf95');
        disp(result)
    end
end

%% OPTIMSED COMPILING (IVF WITH VTUNE DEBUGGING SYMBOLS) - LINUX / UNIX

if user_entry == 3
    [status, result] = system('ifort -c -g -O3 -fast -static-intel -parallel -I/usr/matlab7.6/extern/include -I/usr/matlab7.6/simulink/include -fexceptions -fPIC -DMX_COMPAT_32 "mxmart_large.F90"');
    disp(result)
    if status == 0
        [status, result] = system('ifort -g -O3 -fast -static-intel -parallel -shared -m32 -Wl,--version-script,/usr/matlab7.6/extern/lib/glnx86/fexport.map -Wl,--no-undefined -o "mxmart_large.mexglx" mxmart_large.o "/usr/matlab7.6/extern/lib/glnx86/version4.o" -Wl,-rpath-link,/usr/matlab7.6/bin/glnx86 -L/usr/matlab7.6/bin/glnx86 -lmx -lmex -lmat -lm -L/usr/g95-x86-linux/g95-install/lib/gcc-lib/i686-suse-linux-gnu/4.0.3 -lf95');
        disp(result)
    end
end


%% OPTIMSED COMPILING (IVF - NO DEBUGGING SYMBOLS) - LINUX / UNIX

if user_entry == 4
    [status, result] = system('ifort -c -O3 -fast -static-intel -parallel -I/usr/matlab7.6/extern/include -I/usr/matlab7.6/simulink/include -fexceptions -fPIC -DMX_COMPAT_32 "mxmart_large.F90"');
    disp(result)
    if status == 0
        [status, result] = system('ifort -O3 -fast -static-intel -parallel -shared -m32 -Wl,--version-script,/usr/matlab7.6/extern/lib/glnx86/fexport.map -Wl,--no-undefined -o "mxmart_large.mexglx" mxmart_large.o "/usr/matlab7.6/extern/lib/glnx86/version4.o" -Wl,-rpath-link,/usr/matlab7.6/bin/glnx86 -L/usr/matlab7.6/bin/glnx86 -lmx -lmex -lmat -lm -L/usr/g95-x86-linux/g95-install/lib/gcc-lib/i686-suse-linux-gnu/4.0.3 -lf95');
        disp(result)
    end
end

%% OPTIMSED COMPILING (g95 - NO DEBUGGING SYMBOLS) - LINUX / UNIX
if user_entry == 5
    [status, result] = system('g95 -c -I/usr/matlab7.6/extern/include -I/usr/matlab7.6/simulink/include -fexceptions -fPIC -DMX_COMPAT_32 -O3 -funroll-loops "mxmart_large.F90"');
    disp(result)
    if status == 0
        [status, result] = system('g95 -o3 -pthread -shared -m32 -Wl,--version-script,/usr/matlab7.6/extern/lib/glnx86/fexport.map -Wl,--no-undefined -o "mxmart_large.mexglx" mxmart_large.o "/usr/matlab7.6/extern/lib/glnx86/version4.o" -Wl,-rpath-link,/usr/matlab7.6/bin/glnx86 -L/usr/matlab7.6/bin/glnx86 -lmx -lmex -lmat -lm -L/usr/g95-x86-linux/g95-install/lib/gcc-lib/i686-suse-linux-gnu/4.0.3 -lf95');
        disp(result)
    end
end
%% THE END GAME
if status == 0
    disp('compile_mxmart_large.m: Compilation completed with no errors (any compiler warnings displayed above)')
else
    disp('compile_mxmart_large.m: Errors in compilation - mex file not updated')
end

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Kevin Johnson

Date: 30 Nov, 2009 17:31:04

Message: 5 of 10

Thomas,

Thanks for your detailed reply. I am not a programmer so I will have to find someone here to go over your suggestions with me to help me implement them. I wanted to acknowledge your help before then though.

Kevin

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Kevin Johnson

Date: 2 Dec, 2009 22:05:20

Message: 6 of 10

I've found the solution. The PATH needs to have in it the directory where gfortran is stored, in my case "/usr/local/bin/". However, you cannot add this directory by using the graphical user interface in the Matlab top menu (File...Set path...etc). I guess this is because the Mac hides this and other directories within the Matlab application "package".
I worked around this problem by placing a path statement in my startup.m file as follows:

setenv('PATH', [getenv('PATH') ':/usr/local/bin']);

This is the directory where the GNU gfortran 4.3.0 installer automatically puts the compiler.

I'd be curious if anyone else has had this problem and whether they have found this solution helpful.

Thanks

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Mads A

Date: 5 Mar, 2010 19:00:23

Message: 7 of 10

"Kevin Johnson" <defer.jof@gmail.com> wrote in message <hf6oav$svl$1@fred.mathworks.com>...
> I've found the solution. The PATH needs to have in it the directory where gfortran is stored, in my case "/usr/local/bin/". However, you cannot add this directory by using the graphical user interface in the Matlab top menu (File...Set path...etc). I guess this is because the Mac hides this and other directories within the Matlab application "package".
> I worked around this problem by placing a path statement in my startup.m file as follows:
>
> setenv('PATH', [getenv('PATH') ':/usr/local/bin']);
>
> This is the directory where the GNU gfortran 4.3.0 installer automatically puts the compiler.
>
> I'd be curious if anyone else has had this problem and whether they have found this solution helpful.
>
> Thanks

Same problem. It has to do with MATLAB's shell being located at SHLVL = 3, which means it does not have access to your (Terminal's SHLVL=1) environment variables.

Besides modifying the environment in SHLVL=3, I cannot find out how to get MATLAB to read the SHLVL=1 environment variables (set in .profile for bash).

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: David

Date: 12 Apr, 2010 07:12:03

Message: 8 of 10

Slightly related question:

I'm using Visual C++ 2008 express compiler and that works perfectly. I would now like to test with visual C++ 2010 beta. However after installing and running mex -setup, it is not listed.

How can I link this new compiler? Only the old ones are listed:
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
 
Would you like mex to locate installed compilers [y]/n? y
 
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2009a\sys\lcc
[2] Microsoft Visual C++ 2008 Express in C:\Program Files\Microsoft Visual Studio 9.0
 
[0] None


Thanks

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: Gadi Reinhorn

Date: 26 Jul, 2010 15:17:29

Message: 9 of 10

David,

We have added support for Microsoft Visual C++ 2010 for the current release
of MATLAB (R2010a).
http://www.mathworks.com/support/solutions/en/data/1-D5W493/?solution=1-D5W493

Gadi

Subject: Matlab can't not find g95 or gfortran compiler in MEX-Setting

From: jacob faerman

Date: 26 Jul, 2011 05:38:08

Message: 10 of 10

"Kevin Johnson" wrote in message <hf6oav$svl$1@fred.mathworks.com>...
> I've found the solution. The PATH needs to have in it the directory where gfortran is stored, in my case "/usr/local/bin/". However, you cannot add this directory by using the graphical user interface in the Matlab top menu (File...Set path...etc). I guess this is because the Mac hides this and other directories within the Matlab application "package".
> I worked around this problem by placing a path statement in my startup.m file as follows:
>
> setenv('PATH', [getenv('PATH') ':/usr/local/bin']);
>
> This is the directory where the GNU gfortran 4.3.0 installer automatically puts the compiler.
>
> I'd be curious if anyone else has had this problem and whether they have found this solution helpful.
>
> Thanks

Thanks, this really saved me !

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us