Compiling a MEX file with Visual Studio

Compiling a MEX file with Visual Studio

 

 

 

1) If we are working on matrix multiplication, then after compiling the .br file we generate a .cpp like below. Modify the .cpp file directly to use the MEX API. The sections in bold are the minimum code changes necessary.

 

#include "common.h"

#include "Timer.h"

#include "mex.h"

 

static int retval = 0;

 

//int main(int argc, char** argv)

void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])

{

   

       ...

 

        float A<Height, Width>;

        float B<Width, Height>;

        float C<Height, Height>;

        Start(0);

        streamRead(A, inputA);

        streamRead(B, inputB);

       

        // Run the brook program here

        for (i = 0; i < cmd.Iterations; ++i)

        {

            simple_matmult((float)Width, A, B, C);

        }

 

        // Write data back from stream here

        streamWrite(C, output);

        Stop(0);

 

       ...

 

       mexPrintf("Time to execute matrix multiplication – fast \n");

}

 

 

2) Follow the direction below to build MEX-files with the Microsoft Visual C++ integrated development environment. These are based on:

http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_external/f24338.html&http://www.mathworks.com/support/tech-notes/1600/1605.html

Compiling MEX-Files with the Microsoft® Visual C++® IDE

1.      Create a project (matrix_multiply) and insert your MEX source files. (the .cpp file above)

2.      Add mexversion.rc from the MATLAB include directory, matlab\extern\include, to the project.

3.      Create a .def file to export the MEX entry point. On the Project menu, click Add New Item and select Module-Definition File (.def). For example:

4.     LIBRARY “matrix_multiply.mexw32”
5.     EXPORTS mexFunction          <-- for a C MEX-file
6.        or
EXPORTS _MEXFUNCTION@16       <-- for a Fortran MEX-file

7.      On the Project menu, click Properties for the project to open the property pages.

8.      Under C/C++ General properties, add the MATLAB include directory, matlab\extern\include, as an additional include directory.

9.      Under C/C++ Preprocessor properties, add MATLAB_MEX_FILE as a preprocessor definition.

10.  Under Linker General properties, change the output file extension to .mexw32 if you are building for a 32–bit platform or .mexw64 if you are building for a 64–bit platform.

11.  Locate the .lib files for the compiler you are using under matlabroot\extern\lib\win32\microsoft or matlabroot\extern\lib\win64\microsoft. Under Linker Input properties, add libmx.liblibmex.lib, andlibmat.lib as additional dependencies.

12.  Also under Linker General, add the path to those libraries under “Additional Library Directories”. My path was: "C:\Program Files\MATLAB\R2007b\extern\lib\win32\microsoft")

13.  Under Linker Input properties, add the module definition (.def) file you created if it is not already there).

14.  Under Linker Command Line, add the following as Additional options:

/export:mexFunction /dll

15.  Under Linker Debugging properties, if you intend to debug the MEX-file using the IDE, specify that the build should generate debugging information. For more information about debugging, see Debugging on the Microsoft® Windows®Platforms.

 

This should do it. Now you should have a matrix_multiply.mexw32 file created. You can execute that file in MATLAB by typing: matrix_multiply           in the folder with the file.

 

 转自:http://coachk.cs.ucf.edu/GPGPU/Compiling_a_MEX_file_with_Visual_Studio2.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DriverStudio 3.2 For VisualStudio 2005 补丁<br><br>解决DriverStudio 3.2插件在VisualStudio 2005中无法使用的问题。<br><br>原文件说明:<br><br>Compuware DriverStudio – DriverSuite<br>Version 3.2<br><br>Version 3.2 VisualStudio 2005 Integration fix.<br>The purpose of this update is to allow DriverStudio – DriverSuite to integrate into the VisualStudio 2005 environment<br><br>After extracting the files the result should have been two files and this read me. To install perform the steps below.<br><br>· Close all development environment windows.<br><br>· Copy the file DSDDKEnv8.dll into the <INSTALL_DIR>\DriverStudio\Common\Bin directory. Select "yes" if prompted to copy over an existing one.<br><br>· Copy the file DSDDKEnv8UI.dll into the <INSTALL_DIR>\DriverStudio\Common\Bin\1033 directory. Select "yes" if prompted to copy over an existing one.<br><br>· Then unregister the older version. Go to start->run and type "regsvr32 -u "<INSTALL_DIR>\DriverStudio\Common\Bin\dsddkenv8.dll"<br><br>· Then register the new copy. Go to start->run and type "regsvr32 "<INSTALL_DIR>\DriverStudio\Common\Bin\dsddkenv8.dll"<br><br>Contacting Technical Support<br>For Non-Technical Issues<br>Customer Service is available to answer any questions you might have regarding upgrades, serial numbers and other order fulfillment needs. Customer Service is available from 8:30am to 5:30pm EST, Monday through Friday. Call:<br><br>· In the U.S. and Canada: 1-888-283-9896<br><br>· International: +1-603-578-8103<br><br>For Technical Issues<br>Technical Support can assist you with all your technical problems, from installation to troubleshooting. Before contacting Technical Support, please read the relevant sections of the product documentation and the Readme files.<br><br>You can contact Technical Support by:<br><br>· E-Mail: Include your serial number and send as many details as possible to:<br><br>nashua.support@compuware.com<br><br>· World Wide Web: Submit issues and access additional support services at:<br><br>http://frontline.compuware.com/nashua/<br><br>· Fax: Include your serial number and send as many details as possible to:<br><br>1-603-578-8401<br><br>· Telephone: Telephone support is available as a paid* Priority Support Service from 8:30am to 5:30pm EST, Monday through Friday. Have product version and serial number ready.<br><br>·In the U.S. and Canada, call: 1-888-686-3427<br><br>·International customers, call: +1-603-578-8100<br><br>*Installation Issues: Technical Support handles installation and setup issues free of charge.<br><br>When contacting Technical Support, please have the following information available:<br><br>· Product/service pack name and version.<br><br>· Product serial number.<br><br>· Your system configuration: operating system, network configuration, amount of RAM, environment variables, and paths.<br><br>· The details of the problem: settings, error messages, stack dumps, and the contents of any diagnostic windows.<br><br>· The details of how to reproduce the problem (if the problem is repeatable).<br><br>· The name and version of your compiler and linker and the options that you used in compiling and linking.<br><br> <br><br>Copyright 2005 Compuware Corporation<br>
Contents Introduction Course Materials.........................................................................................2 Prerequisites...............................................................................................3 Course Outline............................................................................................4 Microsoft Certified Professional Program.......................................................6 Facilities.....................................................................................................8 Module 1: Overview of the Microsoft .NET Platform Overview....................................................................................................1 What Is the Microsoft .NET Platform?...........................................................2 What Is the .NET Framework?......................................................................5 What Are the .NET Framework Components?.................................................9 What Are the Visual Basic .NET Enhancements?..........................................17 Review.....................................................................................................19 Module 2: Development Environment Features Overview....................................................................................................1 Describing the Integrated Development Environment.......................................2 Creating Visual Basic .NET Projects..............................................................3 Demonstration: Creating a Visual Basic .NET Project....................................16 Using Development Environment Features...................................................17 Demonstration: Using the Visual Studio .NET IDE........................................29 Debugging Applications.............................................................................30 Demonstration: Debugging a Project............................................................37 Compiling in Visual Basic .NET..................................................................38 Lab 2.1: Exploring the Development Environment.........................................42 Review.....................................................................................................47 Module 3: Language and Syntax Enhancements Overview....................................................................................................1 Data Types.................................................................................................2 Using Variables...........................................................................................9 Demonstration: Using Variables and Data Structures......................................20 Functions, Subroutines, and Properties.........................................................21 Lab 3.1: Working with Variables and Procedures...........................................29 Exception Handling...................................................................................36 Demonstration: Structured Exception Handling.............................................48 Lab 3.2: Implementing Structured Exception Handling...................................49 Review.....................................................................................................52 iv Programming with Microsoft® Visual Basic® .NET (Prerelease) Module 4: Object-Oriented Design for Visual Basic .NET Overview....................................................................................................1 Designing Classes........................................................................................2 Practice: Deriving Classes from Use Cases...................................................10 Object-Oriented Programming Concepts.......................................................11 Advanced Object-Oriented Programming Concepts........................................20 Using Microsoft Visio................................................................................25 Lab 4.1: Creating Class Diagrams from Use Cases.........................................33 Review.....................................................................................................41 Module 5: Object-Oriented Programming in Visual Basic .NET Overview....................................................................................................1 Defining Classes..........................................................................................2 Creating and Destroying Objects.................................................................16 Demonstration: Creating Classes.................................................................23 Lab 5.1: Creating the Customer Class...........................................................24 Inheritance................................................................................................31 Demonstration: Inheritance.........................................................................43 Interfaces..................................................................................................44 Demonstration: Interfaces and Polymorphism...............................................50 Working with Classes................................................................................51 Lab 5.2: Inheriting the Package Class...........................................................65 Review.....................................................................................................74 Module 6: Using Windows Forms Overview....................................................................................................1 Why Use Windows Forms?...........................................................................2 Structure of Windows Forms.........................................................................4 Using Windows Forms...............................................................................12 Demonstration: Manipulating Windows Forms..............................................27 Using Controls..........................................................................................28 Demonstration: Implementing Drag-and-Drop Functionality...........................42 Windows Forms Inheritance........................................................................43 Demonstration: Using Windows Forms Inheritance........................................48 Lab 6.1: Creating the Customer Form...........................................................49 Review.....................................................................................................57 Module 7: Building Web Applications Overview....................................................................................................1 Introduction to ASP .NET.............................................................................2 Creating Web Form Applications.................................................................16 Demonstration: Creating Web Forms...........................................................30 Lab 7.1: Creating the Customer Logon Web Forms........................................31 Building Web Services...............................................................................42 Demonstration: Creating a Web Service.......................................................50 Using Web Services...................................................................................51 Demonstration: Using a Web Service...........................................................57 Multimedia: How Web Services Work.........................................................58 Lab 7.2: Creating and Using the CustomerService Web Service.......................60 Review.....................................................................................................70 Programming with Microsoft® Visual Basic® .NET (Prerelease) v Module 8: Using ADO .NET Overview....................................................................................................1 ADO .NET Overview...................................................................................2 .NET Data Providers....................................................................................5 Demonstration: Retrieving Data Using ADO .NET........................................18 The DataSet Object....................................................................................19 Practice: Using DataSets.............................................................................35 Data Designers and Data Binding................................................................37 XML Integration.......................................................................................45 Demonstration: Using XML Schema............................................................55 Lab 8.1: Creating Applications That Use ADO .NET.....................................56 Review.....................................................................................................69 Module 9: Developing Components in Visual Basic .NET Overview....................................................................................................1 Components Overview.................................................................................2 Creating Serviced Components....................................................................11 Demonstration: Creating a Serviced Component............................................27 Lab 9.1: Creating a Serviced Component......................................................28 Creating Component Classes.......................................................................35 Demonstration: Creating a Stopwatch Component.........................................40 Creating Windows Forms Controls..............................................................41 Demonstration: Creating an Enhanced TextBox.............................................48 Creating Web Forms User Controls..............................................................49 Demonstration: Creating a Simple Web Forms User Control...........................53 Lab 9.2: Creating a Web Forms User Control................................................54 Threading.................................................................................................60 Demonstration: Using the SyncLock Statement.............................................73 Review.....................................................................................................74 Module 10: Deploying Applications Overview....................................................................................................1 Describing Assemblies.................................................................................2 Choosing a Deployment Strategy.................................................................11 Deploying Applications..............................................................................18 Lab 10.1: Packaging a Component Assembly................................................20 Demonstration: Deploying a Web-Based Application.....................................28 Lab 10.2: Deploying a Windows-Based Application......................................29 Review.....................................................................................................33 Module 11: Upgrading to Visual Basic .NET Overview....................................................................................................1 Deciding Whether to Upgrade.......................................................................2 Options for Upgrading.................................................................................7 Recommendations.....................................................................................11 Performing the Upgrade.............................................................................13 Demonstration: Using the Upgrade Wizard...................................................22 Review.....................................................................................................23
matlab在关联编译器的时候 会出现找不到编译器的问题 原因是matlab要找windows sdk的mt exe 本文件修改方法也是根据wiills的那篇“matlab找不到编译器的问题”(matlab无法找到vs2012)的修改方法进行的 请参考:http: download csdn net download wiills 4621079 本次修改如下说明: 1 本次为:Matlab版本为Matlab 2013b(64bit版本)无法关联visual studio 2013编译器的解决方法 2 相对于wiills的修改来说 使用读注册表的方法(不删除添加任何语句 只是修改) 而不是使用绝对路径给出地址 理论上讲如果VS2013的安装路径不是默认的 只要版本对的话把这些文件添加进相对性的目录也是可以关联的 3 使用方法 复制wiills的说明了 哈哈 : 1 把附件相关的5个文件添加到matlab bin win64下面的2个相关目录 2 在matlab 里面运行 mbuild setup 然后选 y 再选择2013的那个项目 再选y 3 这是应该成功了 4 mex setup也是一样的 如果是Matlab 2013b 32位版本的可以复制出matlab bin win64两个相关目录下(mexopts目录下的:msvc110opts stp msvc110opts bat msvc110engmatopts bat和mbuildopts目录下的:msvc110compp bat msvc110compp stp)这五个文件 VS2012的支持文件 对照本文下面给出方法自行修改即可 ">matlab在关联编译器的时候 会出现找不到编译器的问题 原因是matlab要找windows sdk的mt exe 本文件修改方法也是根据wiills的那篇“matlab找不到编译器的问题”(matlab无法找到vs2012)的修改方法进行的 请参考:http: download csdn net downlo [更多]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值