How do I integrate my C++ shared Library generated from MATLAB R2013b in Visual Studio 2013?

16 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
Following are the steps for integrating a C++ shared library in Visual Studio:
1. Compile a C++ shared library in MATLAB R2013b. This will yield 3 files namely the .h file, the .dll file and the .lib file. (for example: foo.h, foo.dll and foo.lib).
    
2. Once you have all the three files, create a new project in Visual Studio which is a Console application.
3. Then right-click on the name of the project and navigate to the Properties.
4.Under the Configuration Properties go to the VC++ Directories. Under the VC++ Directories tab, add the following paths under the Include Directories and the Library Directories 
    a. Path to the folder containing all the three files (foo.lib, foo.h and foo.dll).
    b. Path to <mcrroot>\v82\extern\lib\$arch\microsoft. (Here $arch will be win32 or win64 depending on your Visual Studio build).
   
     
5. Then navigate to General option under the C/C++. In the "Additional Include Directories" add the following path:
    a. <mcrroot>\v82\extern\include
      
6. Next navigate to the General tab under the Linker option in the Properties window. Add the following  path in the "Additional Library Directories" option:
    a. Path to the folder containing all the three files (foo.lib, foo.h and foo.dll)
     
      
7. Then under the Linker ->Input tab add the following to the "Additional Dependencies" option:
    a. mclmcrrt.lib
    b. foo.lib (name of your library that you generated from MATLAB)
     
8. Once the above settings are completed, on the Header files option in the Visual Studio Project, right-click and select "Add existing item". Then navigate to the folder containing all the 3 files (foo.lib, foo.h and foo.dll) and 
    select the foo.h file.
     
9. Using the same procedure under the Resource Files option in the Visual Studio Project, add the .dll and the .lib files (foo.dll and foo.lib).
10. Copy the driver code from foo.cpp into the FooProject.cpp (the C++ source file of this foo project)
11. As a final step, add the folder containing all the three files (foo.h, foo.dll and foo.lib)  on the windows path (i.e: add the path to the folder in the Windows PATH environment variable). Restart Visual Studio.
    
   
12. Follow the steps from 2 to 9 again for Release version (or Debug Version and vice-versa).
                                                 
The attachment zip folder contains the 3 files (foo.lib, foo.h and foo.dll) along with the driver code foo.cpp.
The procedure remains the same for 32-bit or 64-bit builds in Visual studio based on 32-bit or 64-bit MATLAB used for building the shared library.
13. Execute the code by clicking the Local Windows Debugger button. A command prompt like following will be opened which displays the answer

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 C Shared Library Integration 的更多信息

标签

尚未输入任何标签。

产品


版本

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by