VS 编程常见错误及解决方法
1. VS2013 无法打开包括文件:“cv.h"等一些头文件
解决方法:
cv.h是build\include文件夹下的头文件,所在文件夹位置是D:\Program Files (x86)\opencv\build\include\opencv,必须将这个路径添加到OpencvDebugConfiguration.props(见上一篇)中:
2.
错误一:必须属性”VSIstallDir”缺失或为空
解决方式:选择菜单栏的项目->属性->配置属性->常规->平台集成工具,选择V90编辑为V100,点击确定。之后运行就不会再出现必须属性”VSInstallDir”缺失或为空的错误了。
错误二:找不到projectname.exe
解决方式:
1、选择菜单栏的项目->属性->配置属性->VC目录->包含目录->编辑
添加:matlab安装目录\extern\include,然后点击确定
2、选择菜单栏的项目->属性->配置属性->VC目录->库目录->编辑
添加:matlab安装目录\extern\lib\win64\microsoft
3、选择菜单栏的项目->属性->配置属性->C++->常规->附加包目录->编辑,添加:libmx.lib;libeng.lib;libmat.lib; 点击确定
4、选择菜单栏的项目->属性->配置属性->链接器->输入->附加依赖项->编辑,添加:libmx.lib;libeng.lib;libmat.lib; 点击确定
5、选择菜单栏的解决方案平台,选择win64(倘若没有这个选项,则选择配置管理器->选择平台->新建->选择win64->确定即可)
最后得到运行结果:
附上测试代码:
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#include "matrix.h"
#pragma comment(lib,"libeng.lib")
#pragma comment(lib,"libmx.lib")
int main()
{
Engine *ep;
int i , j ;
//show how to open MATLAB engine
//for remote ones:
//engOpen( ADDRESS OF REMOTE SYSTEM ) ;
if (!(ep = engOpen("\0"))){
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
//show how to create matrix
mxArray *Y = mxCreateDoubleMatrix(1 , 3 , mxREAL) ;
//show how to put data in matrix
double tmp[3] = {1.0 , 2.0 , 3.0} ;
memcpy(mxGetPr(Y) , tmp , sizeof(tmp)) ;
//show how to put variables in the Engine
engPutVariable(ep , "Y" , Y) ;
//show how to execute commands in MATLAB
engEvalString(ep, "X = ones(5,1) * Y");
//show how to get variables from the Engine
mxArray *X = engGetVariable(ep , "X") ;
//show how to manipulate dimensions
int dims[10] ;
int ndims ;
ndims = mxGetNumberOfDimensions(X) ;
printf("total number of dimensions is %d\n" , ndims) ;
memcpy(dims , mxGetDimensions(X) , ndims * sizeof(int)) ;
for ( i = 0 ; i < ndims ; i ++ ){
printf("dimension %d : %d\n" , i , dims[i]) ;
}
printf("\n") ;
//show how the data is stored in the memory
double *p = (double*)mxGetData(X) ;
for ( i = 0 ; i < dims[0] ; i ++ ){
for ( j = 0 ; j < dims[1] ; j ++ ){
printf("%8.2f" , p[j * dims[0] + i]) ;
}
printf("\n") ;
}
//---important, to release resources
mxDestroyArray(X) ;
mxDestroyArray(Y) ;
//show how to hide and unhide MATLAB command window
printf("type RETURN to hide the MATLAB command window...\n") ;
getchar() ;
engSetVisible(ep , false) ;
printf("type RETURN to unhide the MATLAB command window...\n") ;
getchar() ;
engSetVisible(ep , true) ;
printf("type RETURN to END this program...\n") ;
getchar() ;
//remembering to close it is important .
//but if you are debugging your programs ,
//annotate the following line will save you a lot of time ,
//for you needn't to restart the Engine .
engClose(ep) ;
//when your work is accomplished , type "exit" in MATLAB command window
return EXIT_SUCCESS;
}