c++ - error in mex: undefined reference to ".." -
i want compile following code mexw64 using ms visual c++ compiler.
balltree.cpp
#define mex #include "balltree.h" #include "mex.h" void mexfunction(int nlhs, mxarray *plhs[], int nrhs, const mxarray *prhs[]) { // check right number of arguments if(nrhs != 2) mexerrmsgtxt("takes 2 input arguments"); if(nlhs != 1) mexerrmsgtxt("outputs 1 result (a structure)"); // points, weights plhs[0] = balltree::createinmatlab(prhs[0],prhs[1]); }
and balltree.h
#ifndef __ball_tree_h #define __ball_tree_h #ifdef mex #include "mex.h" #endif #include <math.h> #include <stdint.h> #define false 0 #define true 1 double log(double); double exp(double); double sqrt(double); double pow(double , double); double fabs(double); #define pi 3.141592653589 class balltree { public: //typedef unsigned int index; // define "index" type (long) typedef uint32_t index; // define "index" type (long) const static balltree::index no_child = (index) -1; // indicates no further children ///////////////////////////// // constructors ///////////////////////////// //balltree( unsigned int d, index n, double* centers_, // double* ranges_, double* weights_ ); #ifdef mex balltree(); balltree(const mxarray* structure); // loading ball trees matlab // creating balltree structures in matlab: static mxarray* createinmatlab(const mxarray* pts, const mxarray* wts); #endif ///////////////////////////// // accessor functions ///////////////////////////// balltree::index root() const { return 0; } unsigned int ndim() const { return dims; } index npts() const { return num_points; } index npts(balltree::index i) const { return highest_leaf[i]-lowest_leaf[i]+1; } const double* center(balltree::index i) const { return centers+i*dims; } const double* range(balltree::index i) const { return ranges +i*dims; } double weight(balltree::index i) const { return *(weights+i); } bool isleaf(balltree::index ind) const { return ind >= num_points; } bool validindex(balltree::index ind) const { return ((0<=ind) && (ind < 2*num_points)); } balltree::index left(balltree::index i) const { return left_child[i]; } balltree::index right(balltree::index i) const { return right_child[i]; } balltree::index leaffirst(balltree::index i) const { return lowest_leaf[i]; } balltree::index leaflast(balltree::index i) const { return highest_leaf[i]; } // convert balltree::index numeric index in original data index getindexof(balltree::index i) const { return permutation[i]; } void movepoints(double*); void changeweights(const double *); // test 2 sub-trees see nearer balltree balltree::index closer(balltree::index, balltree::index, const balltree&,balltree::index) const; balltree::index closer(balltree::index i, balltree::index j, const balltree& other_tree) const { return closer(i,j,other_tree,other_tree.root()); }; void knearestneighbors(index *, double *, const double *, int, int) const; ///////////////////////////// // private class f'ns ///////////////////////////// protected: #ifdef mex static mxarray* matlabmakestruct(const mxarray* pts, const mxarray* wts); #endif virtual void calcstats(balltree::index); // construction recursion unsigned int dims; // dimension of data balltree::index num_points; // # of points double *centers; // ball centers, dims numbers per ball double *ranges; // bounding box ranges, dims per ball, dist center 1 side double *weights; // total weight in each ball balltree::index *left_child, *right_child; // left, right children; no parent indices balltree::index *lowest_leaf, *highest_leaf; // lower & upper leaf indices each ball balltree::index *permutation; // point's position in original data balltree::index next; // internal var placing non-leaf nodes static const char *field_names[]; // list of matlab structure fields static const int nfields; // building ball tree void buildball(balltree::index firstleaf, balltree::index lastleaf, balltree::index root); balltree::index most_spread_coord(balltree::index, balltree::index) const; balltree::index partition(unsigned int dim, balltree::index low, balltree::index high); virtual void swap(balltree::index, balltree::index); // leaf-swapping function void select(unsigned int dimension, index position, index low, index high); double mindist(index, const double*) const; double maxdist(index, const double*) const; // build non-leaf nodes leaves void buildtree(); }; #endif
but following compiler error: " balltree.obj:balltree.cpp:(.text+0x3a): undefined reference balltree::createinmatlab(mxarray_tag const*, mxarray_tag const*)' "
has been noted in toolbox website that:
" ms visual c++ has bug in dealing "static const" variables; think there patch available, or can change these #defines. operate class' parent directory, or add matlab path (e.g. if unzip "myhome/@kde", cd in matlab "myhome" dir, or add path.) ".
i have used compilers such g++ , gcc still fails compile.
your answer right there in @kde/mex/makemex.m (http://www.ics.uci.edu/~ihler/code/kde.tar.gz). build command balltree.cpp is:
mex balltree.cpp cpp/balltreeclass.cc
note have include implementation file (cpp/balltreeclass.cc).
balltree::createinmatlab(...)
defined on line 432 of balltreeclass.cc.
you want run makemex.m instead of trying yourself.
Comments
Post a Comment