请教vc2008编译的问题
时间:2008-07-24 08:28:09
来源:论坛整理 作者: 编辑:chinaitzhe
程序如下:#include <iostream>
#include <math.h>
#include "engine.h"
//using namespace std;
int main()
{
const int N = 50;
double x[N],y[N];
int j = 1;
for (int i=0; i <N; i ) //计算数组x和y
{
x[i] = (i 1);
y[i] = sin(x[i]) j * log(x[i]); //产生-之间的随机数赋给xx[i];
j *= -1;
}
Engine *ep; //定义Matlab引擎指针。
if (!(ep=engOpen(NULL))) //测试是否启动Matlab引擎成功。
{
cout < <"Can't start Matlab engine!" < <endl;
exit(1);
}
//定义mxArray,为行,N列的实数数组。
mxArray *xx = mxCreateDoubleMatrix(1,N, mxREAL);
mxArray *yy = mxCreateDoubleMatrix(1,N, mxREAL); //同上。
memcpy(mxGetPr(xx), x, N*sizeof(double)); //将数组x复制到mxarray数组xx中。
memcpy(mxGetPr(yy), y, N*sizeof(double)); //将数组x复制到mxarray数组yy中。
engPutVariable(ep, "xx",xx); //将mxArray数组xx写入到Matlab工作空间,命名为xx。
engPutVariable(ep, "yy",yy); //将mxArray数组yy写入到Matlab工作空间,命名为yy。
//向Matlab引擎发送画图命令。plot为Matlab的画图函数,参见Matlab相关文档。
engEvalString(ep, "plot(xx, yy); ");
mxDestroyArray(xx); //销毁mxArray数组xx和yy。
mxDestroyArray(yy);
cout < <"Press any key to exit!" < <endl;
cin.get();
engClose(ep); //关闭Matlab引擎。
}
编译的错误提示是这样的:
------ Build started: Project: engine, Configuration: Debug Win32 ------
Compiling...
engine.cpp
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(7) : error C3872: '0x3000': this character is not allowed in an identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(7) : error C2065: ' const' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(7) : error C2144: syntax error : 'int' should be preceded by ';'
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(8) : error C3872: '0x3000': this character is not allowed in an identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(8) : error C2065: ' double' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(8) : error C2146: syntax error : missing ';' before identifier 'x'
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(8) : error C2065: 'x' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(8) : error C2065: 'y' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(9) : error C3872: '0x3000': this character is not allowed in an identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(9) : error C2065: ' int' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(9) : error C2146: syntax error : missing ';' before identifier 'j'
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(9) : error C2065: 'j' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C3872: '0x3000': this character is not allowed in an identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C2144: syntax error : 'int' should be preceded by ')'
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C2065: 'i' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C3861: ' for': identifier not found
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C2065: 'i' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(10) : error C2059: syntax error : ')'
…………
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(37) : error C2065: 'yy' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(37) : error C3861: ' mxDestroyArray': identifier not found
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(39) : error C3872: '0x3000': this character is not allowed in an identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(39) : error C2065: ' cout' : undeclared identifier
e:\my documents\visual studio 2008\projects\engine\engine\engine.cpp(39) : fatal error C1003: error count exceeds 100; stopping compilation
Build log was saved at "file://D:\Program Files\MATLAB\R2007b\extern\include\BuildLog.htm"
engine - 102 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
看错误的原因似乎是因为vc 2008编译器的问题。比如vc2008不支持const int N这样的定义句型吗?
谢谢大家
网友回复:应该是非法字符的问题
手工写代码,试试
网友回复:把代码中多余的空格删除一下
网友回复:果然是和多余的空格有关啊……
谢谢大家!
不过还是不能链接,看来这就是matlab的问题啦
关键字:请教,vc,编译,问题,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面