Pergunta

I am trying to build a source code bundle containing m files and c++ (cpp) source files in Matlab.

The source folder has a simple Matlab Script to compile all cpp files in one folder:

function compileDir_simple(Cdir)
if nargin<1
    Cdir=pwd;
end

files = dir(fullfile(Cdir,'*.cpp'));

oldDir=pwd;
cd(Cdir);
for j=1:length(files)
    try
        cm = sprintf('mex -largeArrayDims %s',files(j).name);
        disp(cm);
        eval(cm);
catch
    disp(lasterr);
    disp('IGNORE if the file is a C++ file which is not a mex file (ie without a     mexFunction inside)');
    end
end

cd(oldDir);

Inside, it uses "mex -largeArrayDims". However, my problem is, when I evaluate that statement Matlab tries to build the selected files by a C compiler which is contained in MATLAB itself. When I call mex -setup I see:

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 D:\MATLAB\R2010a\sys\lcc 

[0] None 

Compiler: 

I installed Bloodshed C++ compiler and added its bin folder ( to the Windows Environment variables, but still I cannot see my C++ compiler in the list of installed compilers. Only Lcc-win32 appears. It will be appropriate to state that it is my first experience on compiling mex files.

Foi útil?

Solução

A mex file on Windows is just a DLL that exports a function named mexFunction. In principle you can compile mex files with any compiler that can create Windows DLLs.

However, to do so using the mex function in MATLAB requires that MATLAB knows about your compiler. And by default MATLAB only has knowledge of a limited number of compilers. Your chosen compiler is not one of them.

Bloodshed is based on mingw. Which means that you should be able to use the Gnumex project to create a mexopts.bat file for use with your compiler.

However, I would be a little sceptical of using Bloodshed here. It is a C++ IDE and I'm not sure you particular need that. I suspect that all you are looking for is a compiler. In which case you would likely be best served by installing plain mingw.

Outras dicas

Bloodshed C++ is not a supported compiler. Check http://www.mathworks.co.uk/support/compilers/R2014a/index.html for a list of supported compilers. Older releases are available from the same page.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top