Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
MatLab and Code::Blocks
zergling:
Good Morning Every one!
I am opening up this thread because I would like to use Matlab with Code::Blocks under Linux Debian.
Could someone please help me out with the settings?
Moreover, is it possible to create a project wizard for matlab?
Bye and thank you very much.
MortenMacFly:
--- Quote from: zergling on January 06, 2011, 03:33:57 am ---Moreover, is it possible to create a project wizard for matlab?
--- End quote ---
Probably you should also start telling what version of C::B you are using. Since 10/05 (and even before) a Matlab wizard at least for S-Functions is present. What shall the wizard do exactly? What have you in mind? A little less information, don't you think?
zergling:
Hi, the version that I am currently using is: svn build rev 6906 (2010-12-27 15:27:55) gcc 4.3.2 Linux/unicode - 64 bit
By playing around, I was able to show the matlab's icon in the project wizard : kdesudo kate /usr/share/codeblocks/templates/wizard/config.script
by removing the if statement in RegisterWizard(wizProject, _T("matlab_csf"), _T("Matlab project"), _T("Console"));
Now my question is: How do I set up the matlab environment in code::blocks?
For example, when I select the matlab location and I click next, I get
The Matlab path you entered seems valid, but this wizard
can't locate the GCC library path in the sub-directory
/extern/lib/win32/gcc
I know that the script is not correct because for what I can see, is for windows. Is there any wizard script for Linux? If not, could you please help me out to configure it out?
Bye and thank you very much.
MortenMacFly:
--- Quote from: zergling on January 06, 2011, 07:23:54 am ---I know that the script is not correct because for what I can see, is for windows. Is there any wizard script for Linux? If not, could you please help me out to configure it out?
--- End quote ---
Ah - I see. Well I did the Matlab wizard for Windows but I don't have access to an Matlab on a Linux environment, that's why it's Windows only atm. However, you can really try to do it yourself (it's very easy) by adopting the script ([C::B]\share\CodeBlocks\templates\wizard\matlab_csf\wizard.script) accordingly. Have a look at other wizards (e.g. the wxWidgets wizard) to see how to detect the OS environment and set the compiler/linker flags accordingly. If you want to you can also use global variables instead of hard-coded path's and let the user make setup the base patch (i.e. installation directory) of Matlab.
If you need assistance, ask here in this forum and I'll see what I can do. I would need (however) at least a list of the Matlab related files and libraries in terms of how and where they are installed in a Linux environment.
zergling:
Hi Morten,
I modified the script like this, but still, it does not work; I am still getting an error such as "The Matlab path you entered seems valid, but this wizard
can't locate the Matlab extern include path in the sub-directory /extern/include"
I have Matlab installed in /media/school/MATLAB/
Moreover, I noticed that the script is looking for /sys/lcc/. I looked in my sys and I do not have that directory I have only fonts, gs8x, jade, java, namespace, opengl, os, tex
Could you please help me out? I really need to fix this problem :(
--- Code: ---////////////////////////////////////////////////////////////////////////////////
//
// Matlab S-Function project wizard
//
////////////////////////////////////////////////////////////////////////////////
// globals
MatlabPath <- _T("");
function BeginWizard()
{
local intro_msg = _T("Welcome to the new Matlab C-S-Function project wizard!\n\n" +
"This wizard will guide you to create a new project\n" +
"creating a Matlab C-S-Function using the GCC\n" +
"or Matlab LCC compiler.\n\n" +
"For GCC you must have converted the Matlab DLL's into\n" +
"GCC compatible libraries using the DLLTOOL before.\n" +
"This wizard expects the GCC libraries at the location:\n" +
"[MATLAB]/extern/lib/win32/gcc\n\n" +
"When you're ready to proceed, please click \"Next\"...");
local matlabpath_descr = _T("Please select the location of Matlab on your computer.\n" +
"This is the top-level folder where Matlab was installed.");
Wizard.AddInfoPage(_T("MatlabCSFIntro"), intro_msg); // intro
Wizard.AddProjectPathPage();
Wizard.AddCompilerPage(_T(""), _T("gcc;lcc"), true, false); // compiler selection but no path selection
Wizard.AddGenericSelectPathPage(_T("MatlabPath"), matlabpath_descr, _T("Please select Matlab's location:"), _T("$(#matlab)"));
Wizard.AddPage(_T("MatlabHint"));
}
////////////////////////////////////////////////////////////////////////////////
// Matlab's path page
////////////////////////////////////////////////////////////////////////////////
function OnLeave_MatlabPath(fwd)
{
if (fwd)
{
local dir = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
local dir_nomacro = ReplaceMacros(dir, true);
if (!IO.DirectoryExists(dir_nomacro))
{
ShowError(_T("Please select a valid path to Matlab..."));
return false;
}
// Verify Matlab extern includes
if (!IO.DirectoryExists(dir_nomacro + _T("/media/school/MATLAB/R2010b/extern/include")))
{
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
"can't locate the Matlab extern include path in the sub-directory /extern/include"));
return false;
}
// Verify Matlab extern tmwtypes.h (Simulink types)
if (!IO.FileExists(dir_nomacro + _T("/media/school/MATLAB/R2010b/extern/include/tmwtypes.h")))
{
ShowError(_T("The Matlab extern path seems valid, but this wizard\n" +
"can't locate the Matlab twmtypes.h in it."));
return false;
}
// Verify Simulink includes
if (!IO.DirectoryExists(dir_nomacro + _T("/media/school/MATLAB/R2010b/simulink/include")))
{
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
"can't locate the Simulink include path in the sub-directory\n"
"/simulink/include"));
return false;
}
// Verify Matlab extern tmwtypes.h (Simulink types)
if (!IO.FileExists(dir_nomacro + _T("/media/school/MATLAB/R2010b/simulink/include/simstruc.h")))
{
ShowError(_T("The Matlab-Simulink include path seems valid, but this wizard\n" +
"can't locate the Matlab simstruc.h in it."));
return false;
}
if (Wizard.GetCompilerID().Matches(_T("lcc")))
{
// Verify LCC includes
if (!IO.DirectoryExists(dir_nomacro + _T("/sys/lcc/include")))
{
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
"can't locate the LCC include path in the sub-directory\n" +
"/sys/lcc/include"));
return false;
}
// Verify LCC libraries
if (!IO.DirectoryExists(dir_nomacro + _T("/extern/lib/win32/lcc")))
{
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
"can't locate the LCC library path in the sub-directory\n" +
"/extern/lib/win32/lcc"));
return false;
}
}
else if (Wizard.GetCompilerID().Matches(_T("gcc")))
{
// Verify GCC libraries
if (!IO.DirectoryExists(dir_nomacro + _T("/extern/lib/win32/gcc")))
{
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
"can't locate the GCC library path in the sub-directory\n" +
"/extern/lib/win32/gcc"));
return false;
}
}
MatlabPath = dir;
}
return true;
}
// return the files this project contains
function GetFilesDir()
{
local result = _T("matlab_csf/files");
if (Wizard.GetCompilerID().Matches(_T("lcc")))
result += _T(";matlab_csf/lccstub");
return result;
}
// setup the already created project
function SetupProject(project)
{
// enable compiler warnings (project-wide)
if (Wizard.GetCompilerID().Matches(_T("lcc")))
{
if (!CompilerFactory.IsValidCompilerID(_T("lcc")))
{
ShowError(_T("The wizard has detected that your version of Code::Blocks does not\n" +
"support the LCC compiler which is required for this project.\n" +
"The wizard cannot continue. Please update Code::Blocks."));
return false;
}
// set project options for LCC
project.SetModeForPCH(pchSourceDir);
project.AddCompilerOption(_T("-Zp8")); // 8 byte alignment
project.AddCompilerOption(_T("-noregistrylookup")); // do not query the registry for libpath
project.AddLinkerOption(_T("-s"));
project.AddLinkerOption(_T("-tmpdir \".\""));
project.AddLinkerOption(_T("-libpath ") + MatlabPath + _T("\\extern\\lib\\win32\\lcc"));
project.AddLinkerOption(MatlabPath + _T("\\extern\\lib\\win32\\lcc\\mexFunction.def"));
}
else if (Wizard.GetCompilerID().Matches(_T("gcc")))
{
// set project options for GCC
project.SetModeForPCH(pchSourceDir);
project.AddCompilerOption(_T("-malign-double")); // 8 byte alignment
project.AddCompilerOption(_T("-fno-exceptions")); // exception free code
project.AddLinkerOption(_T("-shared"));
project.AddLinkerOption(_T("-Wl,--out-implib=sfuntmpl")+DOT_EXT_STATICLIB);
project.AddLibDir(MatlabPath + _T("/extern/lib/win32/gcc"));
}
else
{
ShowError(_T("The selected compiler is not compatible with Matlab.\n" +
"The wizard cannot continue."));
return false;
}
// set common project options (the same for both compilers)
project.AddCompilerOption(_T("-DNDEBUG"));
project.AddCompilerOption(_T("-DMATLAB_MEX_FILE"));
project.AddIncludeDir(MatlabPath + _T("\\extern\\include"));
project.AddIncludeDir(MatlabPath + _T("\\simulink\\include"));
project.AddLinkLib(_T("libmx"));
project.AddLinkLib(_T("libmex"));
project.AddLinkLib(_T("libmatlb"));
project.AddLinkLib(_T("libmat"));
// Debug
local target = project.GetBuildTarget(Wizard.GetDebugName());
if (!IsNull(target))
{
target.SetTargetType(ttDynamicLib);
// the s-function DLL must have the same name as the file/function
target.SetOutputFilename(_T("sfuntmpl") + DOT_EXT_DYNAMICLIB);
target.SetWorkingDir(_T("."));
if (Wizard.GetCompilerID().Matches(_T("lcc")))
{
// It only works that way because the LCC resource compiler does not
// support creating it's "object files" (*.res) in any sub-directory
target.SetObjectOutput(_T(".")); //
}
}
// Release
target = project.GetBuildTarget(Wizard.GetReleaseName());
if (!IsNull(target))
{
target.SetTargetType(ttDynamicLib);
// the s-function DLL must have the same name as the file/function
target.SetOutputFilename(_T("sfuntmpl") + DOT_EXT_DYNAMICLIB);
target.SetWorkingDir(_T("."));
if (Wizard.GetCompilerID().Matches(_T("lcc")))
{
// It only works that way because the LCC resource compiler does not
// support creating it's "object files" (*.res) in any sub-directory
target.SetObjectOutput(_T(".")); //
}
}
return true;
}
--- End code ---
Please let me know if you need more info about my Matlab directories.
Bye and thank you so much for everything.
Navigation
[0] Message Index
[#] Next page
Go to full version