How to use MEX with PCL

8 ビュー (過去 30 日間)
Itzik Ben Shabat
Itzik Ben Shabat 2015 年 5 月 11 日
編集済み: ZZ Hau 2017 年 3 月 5 日
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

採用された回答

Itzik Ben Shabat
Itzik Ben Shabat 2015 年 5 月 14 日
so i solved it eventually. The main problem was that i used C++ in a C file. so first thing i did was to change the file to .cpp instead of .c. Then i got a lot of linker errors which regard different libs. so i inserted all of them manually.
This code finally worked:
if true
% Set the include paths
PCLRoot = 'C:\Program Files\PCL';
IPath1 = ['-I',PCLRoot,'\include\pcl-1.7'];
IPath2=['-I','C:\Program Files\Boost\include'];
IPath3=['-I','C:\Program Files']; %for eigen library
IPath4=['-I','C:\Program Files\flann\include'];
IPath5=['-I','C:\Program Files\VTK 5.8.0\include\vtk-5.8'];
IPath6=['-I','C:\Qt\4.8.0\include'];
IPath7=['-I','C:\Program Files\OpenNI\Include'];
% Set the library paths
LPath1 = ['-L','C:\Program Files\PCL\lib'];
LPath2 = ['-L','C:\Program Files\Boost\lib'];
LPath3 = ['-L','C:\Program Files\VTK 5.8.0\lib\vtk-5.8'];
LPath4 = ['-L','C:\Program Files\flann\lib'];
LPath5 = ['-L','C:\Qt\4.8.0\lib'];
LPath6 = ['-L','C:\Program Files\OpenNI\Lib64'];
lPath1 = ['-l','pcl_io_release.lib'];
lPath2 = ['-l','pcl_common_release.lib'];
lPath3 = ['-l','pcl_kdtree_release.lib'];
lPath4 = ['-l','pcl_search_release.lib'];
lPath5 = ['-l','pcl_features_release.lib'];
mex('YOUR FILE NAME.cpp',IPath1,IPath2,IPath3,IPath4,IPath5,IPath6,IPath7,LPath1,LPath2,LPath3,LPath4,LPath5,LPath6,lPath1,lPath2,lPath3,lPath4,lPath5);
  1 件のコメント
ZZ Hau
ZZ Hau 2017 年 3 月 5 日
編集済み: ZZ Hau 2017 年 3 月 5 日
hi~ Do you try to use pcl KdTreeFLANN in matlab? Because I try to rewrite your example to run KdTreeFLANN,it has many problems.
if true
% code
KNNSearch.obj : error LNK2019: unresolved external symbol "private: void __cdecl pcl::KdTreeFLANN<struct
pcl::PointXYZ,struct flann::L2_Simple<float> >::cleanup(void)"
(?cleanup@?$KdTreeFLANN@UPointXYZ@pcl@@U?$L2_Simple@M@flann@@@pcl@@AEAAXXZ) referenced in function "public: virtual __cdecl
pcl::KdTreeFLANN<struct pcl::PointXYZ,struct flann::L2_Simple<float> >::~KdTreeFLANN<struct
pcl::PointXYZ,struct flann::L2_Simple<float> >(void)"
(??1?$KdTreeFLANN@UPointXYZ@pcl@@U?$L2_Simple@M@flann@@@pcl@@UEAA@XZ) referenced in function
KNNSearch.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl pcl::KdTreeFLANN<struct
pcl::PointXYZ,struct flann::L2_Simple<float> >::setInputCloud(class boost::shared_ptr<class
pcl::PointCloud<struct pcl::PointXYZ> const > const &,class boost::shared_ptr<class std::vector<int,class
std::allocator<int> > const > const &)"
(?setInputCloud@?$KdTreeFLANN@UPointXYZ@pcl@@U?$L2_Simple@M@flann@@@pcl@@UEAAXAEBV?$shared_ptr@$$CBV?$PointCloud@UPointXYZ@pcl@@@pcl@@@boost@@AEBV?$shared_ptr@$$CBV?$vector@HV?$allocator@H@std@@@std@@@4@@Z)
KNNSearch.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl pcl::KdTreeFLANN<struct
pcl::PointXYZ,struct flann::L2_Simple<float> >::nearestKSearch(struct pcl::PointXYZ const &,int,class
std::vector<int,class std::allocator<int> > &,class std::vector<float,class std::allocator<float> > &)const "
(?nearestKSearch@?$KdTreeFLANN@UPointXYZ@pcl@@U?$L2_Simple@M@flann@@@pcl@@UEBAHAEBUPointXYZ@2@HAEAV?$vector@HV?$allocator@H@std@@@std@@AEAV?$vector@MV?$allocator@M@std@@@5@@Z)
KNNSearch.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl pcl::KdTreeFLANN<struct
pcl::PointXYZ,struct flann::L2_Simple<float> >::radiusSearch(struct pcl::PointXYZ const &,double,class
std::vector<int,class std::allocator<int> > &,class std::vector<float,class std::allocator<float> > &,unsigned
int)const "
(?radiusSearch@?$KdTreeFLANN@UPointXYZ@pcl@@U?$L2_Simple@M@flann@@@pcl@@UEBAHAEBUPointXYZ@2@NAEAV?$vector@HV?$allocator@H@std@@@std@@AEAV?$vector@MV?$allocator@M@std@@@5@I@Z)
KNNSearch.mexw64 : fatal error LNK1120: 4 unresolved external symbol
end

サインインしてコメントする。

その他の回答 (1 件)

Gil Elbasos
Gil Elbasos 2016 年 4 月 4 日
It is kind of sad how you answered yourself. I am happy that it worked for you.
-G

カテゴリ

Help Center および File ExchangeDeploy to C++ Applications Using MATLAB Data API (C++11) についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by