c++调用matlab函数——配置
2014-10-30 15:32
447 查看
To compile a MATLAB engine application in the Microsoft Visual Studio 9.0 (2008) or Microsoft Visual Studio 10.0 (2010) environments, perform the steps outlined below:
1. Open Microsoft Visual Studio and select
File->New->Project
and then select:
Visual C++ -> General -> Empty Project
Following this, enter the name of the project and its location in the indicated text areas and click OK.
2. Right-click on the SOURCE FILES folder in the SOLUTION EXPLORER and click Add -> "New Item...". Choose "C++ file (.cpp)", enter the name of the file as enginedemo.cpp. Click OK.
3. Copy the code from the source file: engwindemo.c, and paste it into this file enginedemo.cpp. The file engwindemo.c may be obtained from the following location:
where $MATLABROOT is the MATLAB root directory, and may be determined by entering the command:
at the MATLAB command prompt.
4. Right click on the project name and select PROPERTIES in the solution explorer to open the project properties. Once this window has opened, make the following changes:
a. Under C/C++ General, add the following directory to the field ADDITIONAL INCLUDE DIRECTORIES:
$MATLABROOT\extern\include
b. Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
c. Under Linker General, add the directory to the field ADDITIONAL LIBRARY DIRECTORIES:
(For 32-bit Windows)
$MATLABROOT\extern\lib\win32\microsoft
(For 64-bit Windows)
$MATLABROOT\extern\lib\win64\microsoft
d. Under Configuration Properties ->Debugging
Add the following Target path in the Environment:
(for 32 bit MATLAB)
PATH=$matlabroot\bin\win32
(for 64-bit MATLAB)
PATH=$matlabroot\bin\win64
7. Under Linker Input, add the following names to the field marked ADDITIONAL DEPENDENCIES:
libmx.lib
libmat.lib
libeng.lib
8. If compiling on 64-bit Windows, change the target to x64 as mentioned on the following link:
http://msdn2.microsoft.com/en-us/library/9yb4317s(VS.80).aspx
You should now be able to build the executable.
9. Make sure that the following directory is in the PATH:
(For 32-bit Windows)
$MATLABROOT\bin\win32
(For 64-bit Windows)
$MATLABROOT\bin\win64
To do this, check the Windows system path by clicking on Start -> Right click on Computer -> Properties -> Advanced System Settings -> Environment variables -> System Variables -> Open "Path" for editing.
Note: If the machine has more than one MATLAB installed, the directory for the target platform must be ahead of any other MATLAB directory (for instance, when compiling a 64-bit application, the directory in the MATLAB 64-bit installation must be the first
one on the PATH).
10. Build and execute the application.
1. Open Microsoft Visual Studio and select
File->New->Project
and then select:
Visual C++ -> General -> Empty Project
Following this, enter the name of the project and its location in the indicated text areas and click OK.
2. Right-click on the SOURCE FILES folder in the SOLUTION EXPLORER and click Add -> "New Item...". Choose "C++ file (.cpp)", enter the name of the file as enginedemo.cpp. Click OK.
3. Copy the code from the source file: engwindemo.c, and paste it into this file enginedemo.cpp. The file engwindemo.c may be obtained from the following location:
$MATLABROOT/extern/examples/eng_mat
where $MATLABROOT is the MATLAB root directory, and may be determined by entering the command:
matlabroot
at the MATLAB command prompt.
4. Right click on the project name and select PROPERTIES in the solution explorer to open the project properties. Once this window has opened, make the following changes:
a. Under C/C++ General, add the following directory to the field ADDITIONAL INCLUDE DIRECTORIES:
$MATLABROOT\extern\include
b. Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
c. Under Linker General, add the directory to the field ADDITIONAL LIBRARY DIRECTORIES:
(For 32-bit Windows)
$MATLABROOT\extern\lib\win32\microsoft
(For 64-bit Windows)
$MATLABROOT\extern\lib\win64\microsoft
d. Under Configuration Properties ->Debugging
Add the following Target path in the Environment:
(for 32 bit MATLAB)
PATH=$matlabroot\bin\win32
(for 64-bit MATLAB)
PATH=$matlabroot\bin\win64
7. Under Linker Input, add the following names to the field marked ADDITIONAL DEPENDENCIES:
libmx.lib
libmat.lib
libeng.lib
8. If compiling on 64-bit Windows, change the target to x64 as mentioned on the following link:
http://msdn2.microsoft.com/en-us/library/9yb4317s(VS.80).aspx
You should now be able to build the executable.
9. Make sure that the following directory is in the PATH:
(For 32-bit Windows)
$MATLABROOT\bin\win32
(For 64-bit Windows)
$MATLABROOT\bin\win64
To do this, check the Windows system path by clicking on Start -> Right click on Computer -> Properties -> Advanced System Settings -> Environment variables -> System Variables -> Open "Path" for editing.
Note: If the machine has more than one MATLAB installed, the directory for the target platform must be ahead of any other MATLAB directory (for instance, when compiling a 64-bit application, the directory in the MATLAB 64-bit installation must be the first
one on the PATH).
10. Build and execute the application.
相关文章推荐
- matlab中调用c++函数
- Linux下c++调用自己编写的matlab函数:通过shell script system command实现
- matlab函数编译成库供C++调用(非常详细)
- C++调用matlab函数实现微信自动跳一跳
- [matlab]--调用不同路径下函数的方法(类似c++#include(xxx))
- VC6.0配置LUA编译环境及LUA调用C++函数的简单示例
- matlab调用c++函数
- C++和Matlab混合编程——MATLAB调用c++函数(以svmlight为例)
- MATLAB中调用c++程序(函数)
- Java调用Matlab函数以及同时配置多版本JDK的方法
- Linux下c++调用自己编写的matlab函数:通过mcc动态链接库.so实现
- RGB 转换 Ycbcr 调用 C++和MATLAB中的函数,得到了两种不同的运算结果
- matlab调用opencv函数的配置
- ubuntu c/c++中调用matlab函数
- c++与matla混合编程之一---调用matlab工具箱内的函数
- Linux下c++调用自己编写的matlab函数:通过matlab引擎实现
- C/C++下调用matlab函数操作说明
- Linux下c++调用自己编写的matlab函数:通过mcc动态链接库.so实现
- C++程序调用Python的函数(简单应用)及Ubuntu16.04下codeblocks的环境配置
- MATLAB与C++/MFC混合编程;调用MATLAB函数