WARP Project Forums - Wireless Open-Access Research Platform

You are not logged in.

#1 2014-Apr-14 15:11:10

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Question about using MEX function for Matlab 2014a

Hey,

I try to implement MEX function for udp transport using Matlab 2014a.
The problem that I encountered was that Microsoft Visual C++ 2010 Express is not supported by Matlab 2014a.
According to: http://www.mathworks.com/support/compilers/R2014a/
Unlike to other version, e.g. 2011: http://www.mathworks.com/support/compil … win32.html
Microsoft Visual C++ 2010 Express are supported in other version.
Can I use other Microsoft Visual C++ version instead of 2010?
If not, is there anyway that I can use Matlab 2014a to implement Mex function for udp transport?
Thanks!

Offline

 

#2 2014-Apr-14 17:27:39

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Question about using MEX function for Matlab 2014a

We have only officially tested the MEX with the Microsoft Visual C++ 2010 Express on Windows. 

However, the MEX C code should be able to be compiled in the later compilers.  The code relies on the wsock32 and Kernel32 libraries in Windows.  If you have a later compiler, you can try it yourself.  We will be looking at what official version to support for Matlab 2014a in the near future.

If you get any errors with other compilers, please post them.

Offline

 

#3 2014-Apr-15 08:13:40

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Re: Question about using MEX function for Matlab 2014a

Hi Welsh,

I try to use Microsoft Visual C++ 2013 Professional.
I can set Microsoft Visual C++ 2013 professional as compiler, but when I run the command "which wl_mex_udp_transport".
For automatic compilation, The error message is "Error using wl_mex_udp_transport (line 144)
Please install "Microsoft Visual C++ 2010 Express" and re-run wl_mex_udp_transport.  \nSee
http://warpproject.org/trac/wiki/WARPLab/MEX for more information".
For manual compilation, when I run "mex -g -O wl_mex_udp_transport.c -lwsock32 -lKernel32 -DWIN32 ", it gives me the error:
"Warning: MEX cannot find library 'wsock32'. Defaulting to 'libwsock32.lib'.
Warning: MEX cannot find library 'Kernel32'. Defaulting to 'libKernel32.lib'.
Building with 'Microsoft Visual C++ 2013 Professional (C)'.
Error using mex
LINK : fatal error LNK1104: cannot open file 'libwsock32.lib'"

It seems that I can't use compiler other than Microsoft Visual C++ 2010 Express.
Do you have any suggestions?

Offline

 

#4 2014-Apr-15 10:01:38

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Question about using MEX function for Matlab 2014a

Have you installed the Windows SDK 7.1?

There is a basic how to compile MEX guide that we put together.  See if following that fixes the problem.

Offline

 

#5 2014-Apr-15 10:27:02

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Re: Question about using MEX function for Matlab 2014a

Thanks for your reply.
I have installed  Windows SDK 7.1.
From mex -setup, I can set the compiler to Windows SDK 7.1 or Visual C++ 2013 Professional.
If I set compiler as Windows SDK 7.1 instead of Visual C++ 2013 Professional.
For automatic and manual compilation, it still gives me the same error as before.

Offline

 

#6 2014-Apr-15 11:14:37

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Question about using MEX function for Matlab 2014a

If you open Windows Explorer, can you find:   

Code:

C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64\WSock32.lib
C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64\Kernel32.lib

These are the two libraries that the MEX is trying to link against.  One thing you can try is to specify library paths manually in the mex compile command.  While in the M_Code_Reference/mex directory, run:

Code:

mex -g -O wl_mex_udp_transport.c '-LC:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64' -lwsock32 -lKernel32 -DWIN32

Offline

 

#7 2014-Apr-15 11:28:57

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Question about using MEX function for Matlab 2014a

Another thing to look at is:

C:\Users\<your_user_name>\AppData\Roaming\MathWorks\MATLAB\R2011a\mexopts.bat

where <your_user_name> is your windows login username (or you can see where mexopts.bat is located when you run mex -setup).

If you look in the file, you can see the default search paths that MATLAB is using during the MEX compile.  The "LIB" variable is the default library search path and needs to have a path containing WSock32.lib and Kernel32.lib in it.  Otherwise, you will always have to manually specify the library path for the MEX compile.

Offline

 

#8 2014-Apr-15 15:53:33

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Re: Question about using MEX function for Matlab 2014a

According to http://www.mathworks.com/matlabcentral/ … onal-2013, mex function doesn't use bat files in Matlab 2014a.
Does this change has any impact on WARPLab MEX Compilation?

There is still some linkage problem in my case.
If I run "mex -g -O wl_mex_udp_transport.c '-LC:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64' -lwsock32 -lKernel32 -DWIN32", it works.
Then I run "wl_setup", the error is
"Undefined function 'inifile' for input arguments of type 'char'
adding path 'C:\Users\GNAN\Xilinx\WARPLab_Reference_Design_7.4.0\config'
Warning: Name is nonexistent or not a directory: C:\Users\GNAN\Xilinx\WARPLab_Reference_Design_7.4.0\config".
What should I do for this error?

Offline

 

#9 2014-Apr-15 16:10:34

murphpo
Administrator
From: Mango Communications
Registered: 2006-Jul-03
Posts: 5159

Re: Question about using MEX function for Matlab 2014a

If I run "mex -g -O wl_mex_udp_transport.c '-LC:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64' -lwsock32 -lKernel32 -DWIN32", it works.

Ok, great- thanks for posting this. We'll update the recommendations for compiling mex to include this variation.

What was your 'mex -setup' when this finally worked (i.e. which compiler was selected)?

Then I run "wl_setup", the error is
"Undefined function 'inifile' for input arguments of type 'char'
adding path 'C:\Users\GNAN\Xilinx\WARPLab_Reference_Design_7.4.0\config'
Warning: Name is nonexistent or not a directory: C:\Users\GNAN\Xilinx\WARPLab_Reference_Design_7.4.0\config".
What should I do for this error?

What is MATLAB's current working directory when you run wl_setup? You should first CD to the M_Code_Reference folder of the expanded reference design .zip archive, then run 'wl_setup' directly on the MATLAB command line.

Offline

 

#10 2014-Apr-15 17:46:48

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Re: Question about using MEX function for Matlab 2014a

Microsoft Visual C++ 2013 Professional was selected as compiler.
I run "wl_setup" in mex folder in M_Code_Reference folder.
In step 5), should I run "wl_setup" in  M_Code_Reference folder?

1) Please familiarize yourself with the process at:
         http://warpproject.org/trac/wiki/WARPLab/MEX
       to make sure your environment is set up properly.
    2) Set up mex to choose your compiler.  (mex -setup)
         1. Select "Yes" to have mex locate installed compilers
         2. Select "Microsoft Visual C++ 2010 Express"
         3. Select "Yes" to verify your selections
    3) Change directory to M_Code_Reference/mex (cd mex)
    4) Run the compile command:
         mex -g -O wl_mex_udp_transport.c -lwsock32 -lKernel32 -DWIN32
    5) Re-run wl_setup and make sure that "WARPLab Mex UDP" is an available transport.

Offline

 

#11 2014-Apr-15 17:55:13

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Question about using MEX function for Matlab 2014a

Yes.  wl_setup only lives in M_Code_Reference and does not get put in your MATLAB path.  This was done so that when you run wl_setup, you know which version of WARPLab you are installing in to your MATLAB path (wl_setup removes other WARPLab installations from your MATLAB path).

The steps should really be:

5) Change directory back to M_Code_Reference (cd ..)
6) Re-run wl_setup and make sure that "WARPLab Mex UDP" is an available transport.

Offline

 

#12 2014-Apr-15 19:48:10

jasper1107
Member
Registered: 2014-Apr-11
Posts: 28

Re: Question about using MEX function for Matlab 2014a

Thanks a lot!
I can use WARPLab with mex function right now.
Just want to remind, the mex -setup in 2014a is a little bit different.
To set the compiler, you can run "mex -setup" and directly click the compiler name from command window.
Or you can set compiler as Microsoft Visual C++ 2013 Professional by "mex -setup:C:\Users\GNAN\AppData\Roaming\MathWorks\MATLAB\R2014a\mex_C_win64.xml C"

Offline

 

#13 2014-Apr-15 19:57:10

murphpo
Administrator
From: Mango Communications
Registered: 2006-Jul-03
Posts: 5159

Re: Question about using MEX function for Matlab 2014a

Great to hear it's working. And thank you for providing the very good feedback. We (obviously) hadn't tried MATLAB 2014a yet. We'll make sure these new issues are addressed in the next WARPLab release.

Offline

 

Board footer