Author Topic: matlab set  (Read 5853 times)

Offline andy2008

  • Single posting newcomer
  • *
  • Posts: 8
matlab set
« on: November 27, 2017, 09:22:53 am »
hello,everyone.i am a new learner and want to use the codeblocks to write matlab c mex function.
when i go with the matlab project wizard,i meet some problems.firstly i try to solve it myself and serach many ,but still can't get it.
so i want some help from problems below:
1、the version of CB is 16.01 , the matlab is r2016b x64. the compiler is MinGW64 4.9.2
2、when i use the wizard to begin a matlab project , there are problems in the matlab' location.
    the erro is : the matlab path you entered valid ,but this wizard can't locate the GCC library path in
    the sub-directory /extern/lib/win32/gcc.
    i check my the folder' location which is C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64.
  so can i use the wizard to creat matlab project?
thanks everyone for consideration.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: matlab set
« Reply #1 on: November 27, 2017, 03:54:49 pm »
You can set up the project by yourself. You don't need the wizard. The wizard script is probably old, but you can try to fix it by yourself. And if all works you can post a patch here.

Lets try to fix the wizard first (i can not get matlab, so i can only try to help you blind...)
You can edit the wizard script:
File->New->Project->Matlab Project->Right click->Edit script
You will get a error message, you have to confirm it with "yes"
In line 104 you can edit the path to the compiler files, so in your case you should edit this path to "/extern/lib/win64/doc"
The next path would be in line 167

You can try this and if you get any compiler error:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: matlab set
« Reply #2 on: November 27, 2017, 03:59:12 pm »
Also can you give some link where i can read about setting up matlab mex?

Offline andy2008

  • Single posting newcomer
  • *
  • Posts: 8
Re: matlab set
« Reply #3 on: November 28, 2017, 06:14:22 am »
thank u very much. i read the script and do as recommendation.
as the version  is old , so i decide not use the wizard.
i read the matlab help, and find something useful,but there are also some questions.
the help document is telling how to use the VS C++ to compile mex files.(see attach)
i want to do the same with CB.
but i don't know how to control the output file extension using .mexw64.

hope you a happy day

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: matlab set
« Reply #4 on: November 28, 2017, 05:55:57 pm »
We (I) still need more context. I have no idea what mex files are. Do you need to compile them? Is this a output file of matlab?


Because i don't know what mex files are i can not help with steps 1) and 2). Also what is the end result of this? A library or a  executable? Do you export functions from matlab and use them in your program, or do you export your own functions to matlab?

Create a project with the corresponding wizard (console application or library, i don't know what your output is)
From there on it should be straight forward:

3) Project->Build options
4) Select the project target on the left->Search directories->Compiler Add the right include folder
5) Select the project target on the left->Compiler settings->#defines add MATLAB_MEX_FILE
Close this dialog
6) Project->Properties->Build targets->Select a target on the left (probably debug)->Change the output filename to the extension .mexw64->Remove thick from "Auto generate filename prefix" and "Auto generate filename extension"
Close this dialog with ok
7) Project->Build options->Select the project target on the left->Linker settings->Add the libraries you need (you can add only the names)
 Project->Build options->Select the project target on the left->Search directories->Linker->Add the path to the libraries

NOTE: if you are using the mingw compiler you can NOT use the .lib files but there should be .a files.
NOTE: For simplicity: You have to use the SAME compiler as matlab used to generate the .a files (same version, same fork, same everything)
NOTE: You can use the .lib files, but this is getting difficult: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs

8 ) I have no idea.... Probably someone else can help you, but as far as i know, if you are using mingw compiler you do not need def files
9) Codeblocks has done this automatically for the debug target
« Last Edit: November 28, 2017, 05:58:28 pm by BlueHazzard »

Offline andy2008

  • Single posting newcomer
  • *
  • Posts: 8
Re: matlab set
« Reply #5 on: November 29, 2017, 04:02:56 am »
i really really thank u so much. i have been at a loss for some days.
Today i successfully gain what i want.
because i have tried to do that in VS, i searched many webs and  finally know one thing the mex files is a dll in nature.
the mex files is a dll several years before , and now the file extension is mexw64/32.
we can use the  C  to write functions under the matlab 's requirement and export mexw64/32 files from IDE or matlab,then in the matlab we can call the mexw64/32 files.
thanks for your notes, but i alos found i can use the .lib files.Thayt makes things simple.
the compiler in my computer is TDD-GCC-mingw64 4.9.2.maybe after installation,the program creat a folder in C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64.
i set the above path in  Project->Build options->Select the project target on the left->Search directories->Linker->Add the path.
i also install  the gnumex , but i think it has no use.maybe the new version matlab don't need it.

In the last I highly appreciate your help .  i 'm in china ,and  serarch mamy webs and find something a bit useful. so i seek for help in this forums.
so sorry for bothering you. hope you  a happy day


Offline andy2008

  • Single posting newcomer
  • *
  • Posts: 8
Re: matlab set
« Reply #6 on: November 29, 2017, 03:59:08 pm »
Hi, i found a reply in the forums which says we don't need to convert the Matlab DLL's into GCC compatible libraries.
I get the screenshot and set it in the attachments.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: matlab set
« Reply #7 on: November 29, 2017, 06:47:45 pm »
So you still need help? If so please ask concrete questions or show error logs.

Quote
Hi, i found a reply in the forums which says we don't need to convert the Matlab DLL's into GCC compatible libraries.
This probably works only if the exported functions are all C functions. If C++ is involved this won't work for sure, because mingw and msvc use different name mangling....

Offline andy2008

  • Single posting newcomer
  • *
  • Posts: 8
Re: matlab set
« Reply #8 on: November 30, 2017, 01:33:28 am »
Hi, a happy day.
I believe i still need some help in the future,while now i need to go deep into the matlab' help.
In most situations, i only use C functions.If C++ is involved, i will do some try.
Thanks for your help.