How to use MEX with PCL
Show older comments
Hi, so im new to mex but very familiar with matlab. im trying to use PCL with MEX but i keep getting a lot of errors that i dont know how to solve. it seems to have something to do with the line
#include <pcl/features/feature.h>
I tried everything i could find online but no luck. does anyone know how to solve this ? I am using win6 64bit and msvc 2010. I attached my codes nd error list below
Here is my matlab code :
if true
clear all
close all
clc
PCLRoot = 'C:\Program Files\PCL';
IPath1 = ['-I',PCLRoot,'\include\pcl-1.7'];
IPath2=['-I','C:\Program Files\Boost\include'];
IPath3=['-I','C:\Program Files\MATLAB\R2014b\extern\include\matrix.h'];
LPath1 = ['-L',fullfile(PCLRoot, 'lib')];
LPath2 = ['-L','C:\Program Files\Boost\lib\libboost_system-vc100-mt-1_50.lib'];
mex('NormalCalc.c', IPath1,IPath2,IPath3, LPath1,LPath2);
filename='rhino.pcd';
P = loadpcd(filename);
%pclviewer(P);
Normals=NormalCalc(P);
end
and here is my mex file (soing something really basic now - just transferring data from points to normals)
if true
% code
/*
* NormalCalc.c - calculates normals of point cloud
*
*
* points: a 3xN matrix (inMatrix)
* normals: outputs a 3xN matrix (outMatrix)
*
* The calling syntax is:
*
* outMatrix = arrayProduct(multiplier, inMatrix)
*
* This is a MEX-file for MATLAB.
*/
#include "mex.h"
#include <pcl/features/feature.h>
//typedef pcl::PointXYZRGBA PointT;
//typedef pcl::PointCloud<PointT> PointCloud;
/* The computational routine */
void NormalCalc(float *points, double *normals,int npoints){
mwSize i;
for (i=0; i<3*npoints; i++) {
normals[i]=(double) points[i];
mexPrintf("%f\n",points[i]);
}
}
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
/* variable declarations here */
float *inMatrix; /* 3xN input matrix */
mwSize npoints; /* size of matrix */
double *outMatrix; /* output matrix */
/* code here */
/* check for proper number of arguments */
if(nrhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nrhs",
"one inputs required.");
}
if(nlhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nlhs",
"One output required.");
}
/* check that number of rows in points input argument is 3 */
if(mxGetM(prhs[0])!=3) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notRowVector",
"Input must be a 3 row vector.");
}
/* create a pointer to the real data in the input matrix */
inMatrix = mxGetPr(prhs[0]);
/* get dimensions of the input matrix = number of points */
npoints = mxGetN(prhs[0]);
/* create the output matrix */
plhs[0] = mxCreateDoubleMatrix(3,npoints,mxREAL);
/* get a pointer to the real data in the output matrix */
outMatrix = mxGetPr(plhs[0]);
/* call the computational routine */
NormalCalc(inMatrix, outMatrix,npoints);
}
end
here is the list of errors :
if true
Error using mex
NormalCalc.c
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(19) : error C2054: expected
'(' to follow 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(19) : error C2061: syntax
error : identifier 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(19) : error C2054: expected
'(' to follow 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax
error : identifier 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax
error : identifier 'abs'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(21) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax
error : identifier 'atexit'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(21) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax
error : identifier 'atof'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax
error : identifier 'atoi'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax
error : identifier 'atol'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(22) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax
error : identifier 'bsearch'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax
error : identifier 'calloc'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax
error : identifier 'div'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(23) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2061: syntax
error : identifier 'exit'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2061: syntax
error : identifier 'free'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2061: syntax
error : identifier 'getenv'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(24) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2061: syntax
error : identifier 'labs'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2061: syntax
error : identifier 'ldiv'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2061: syntax
error : identifier 'malloc'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(25) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2061: syntax
error : identifier 'mblen'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2061: syntax
error : identifier 'mbstowcs'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2061: syntax
error : identifier 'mbtowc'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(26) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2061: syntax
error : identifier 'qsort'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2061: syntax
error : identifier 'rand'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2061: syntax
error : identifier 'realloc'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(27) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2061: syntax
error : identifier 'srand'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2061: syntax
error : identifier 'strtod'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2061: syntax
error : identifier 'strtol'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(28) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(29) : error C2061: syntax
error : identifier 'strtoul'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(29) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(29) : error C2061: syntax
error : identifier 'system'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(29) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(30) : error C2061: syntax
error : identifier 'wcstombs'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(30) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(30) : error C2061: syntax
error : identifier 'wctomb'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(30) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(32) : error C2054: expected
'(' to follow 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(34) : error C2061: syntax
error : identifier 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(34) : error C2061: syntax
error : identifier 'lldiv'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstdlib(34) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstddef(18) : error C2054: expected
'(' to follow 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cstddef(18) : error C2061: syntax
error : identifier 'using'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(78) : error C2143: syntax
error : missing '{' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(78) : error C2059: syntax
error : '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(87) : error C2143: syntax
error : missing '{' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(87) : error C2059: syntax
error : '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(98) : error C2061: syntax
error : identifier 'tr1'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(98) : error C2059: syntax
error : ';'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(98) : error C2449: found '{'
at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(101) : error C2059: syntax
error : '}'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(125) : error C2143: syntax
error : missing '{' before ':'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(125) : error C2059: syntax
error : ':'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(132) : error C2143: syntax
error : missing '{' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(132) : error C2059: syntax
error : '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(141) : error C2143: syntax
error : missing '{' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xstddef(141) : error C2059: syntax
error : '<'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\eh.h(26) : fatal error C1189: #error :
"eh.h is only for C++!"
end
Accepted Answer
More Answers (1)
Gil Elbasos
on 4 Apr 2016
0 votes
It is kind of sad how you answered yourself. I am happy that it worked for you.
-G
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!