簡體   English   中英

Matlab R2015b 64位使用mex時出錯

[英]Matlab R2015b 64 bits Error using mex

我想使用Matlab R2015b編譯以下代碼

#include "mex.h"
#include "GLTree.cpp"
/* the gateway function */
//la chiamata deve essere DeleteGLtree(Tree)

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


//dichiarazione variabili
GLTREE* Tree;
double *ptrtree;



 if(nrhs!=1){ mexErrMsgTxt("Only one input supported.");}




ptrtree = mxGetPr(prhs[0]);//puntatore all'albero precedentemente fornito


Tree=(GLTREE*)((long)(ptrtree[0]));//ritrasformo il puntatore passato

if(Tree==NULL)
{ mexErrMsgTxt("Invalid tree pointer");
}


//chiamo il distruttore

 delete Tree;  }

但我收到此錯誤“ C:\\ Users \\ Admin \\ Documents \\ MATLAB \\ GraphSeg \\ GLtree3DMex \\ DeleteGLTree.cpp:15:38:警告:從不同大小的整數強制轉換為指針[-Wint-to-pointer-cast]樹=(GLTREE *)((長)(ptrtree [0]));”

您錯誤地聲明了mexFunction。 您的聲明:

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

不等於:

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

回答你的問題

您需要將const mxArray *plhs[]

進一步的評論:

您可能想在將內存地址從mex函數傳遞回MATLAB時檢查此鏈接。 我的直覺是,您隨意使用double並強制轉換為long(甚至是long long)可能會遇到很大的問題……這確實應該是uin64,並且出於魯棒性,您可能需要一些其他的編譯檢查,以檢查類型全部匹配,因為一切都是8字節... http://www.mathworks.com/matlabcentral/answers/75524-returning-and-passing-void-pointers-to-mex-functions

這是基於您的代碼的猜測(我沒有編譯):在64位計算機上,地址空間具有大小為8個字節(64位)的指針,並且您將一個指針強制轉換為long類型(可能只有4個字節)長。 如果要強制轉換,則應使用8字節長的類型,例如long long (保證至少為8字節)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM