墨西哥错误:未定义对".."的引用
error in mex: undefined reference to ".."
我想使用MS visual C++编译器将以下代码编译到mexw64。
BallTree.cpp
#define MEX
#include "BallTree.h"
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// check for the right number of arguments
if(nrhs != 2)
mexErrMsgTxt("Takes 2 input arguments");
if(nlhs != 1)
mexErrMsgTxt("Outputs one result (a structure)");
// points, weights
plhs[0] = BallTree::createInMatlab(prhs[0],prhs[1]);
}
和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); // for loading ball trees from matlab
// For 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 a BallTree::index to the numeric index in the original data
index getIndexOf(BallTree::index i) const { return permutation[i]; }
void movePoints(double*);
void changeWeights(const double *);
// Test two sub-trees to see which is nearer another 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 from center to one 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 for each ball
BallTree::index *permutation; // point's position in the original data
BallTree::index next; // internal var for placing the non-leaf nodes
static const char *FIELD_NAMES[]; // list of matlab structure fields
static const int nfields;
// for building the 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 the non-leaf nodes from the leaves
void buildTree();
};
#endif
但我得到以下编译器错误:" BallTree.obj:BallTree.cpp:(.text+0x3a): undefined reference to BallTree::createInMatlab(mxArray_tag const*, mxArray_tag const*)' "
工具箱网站上也注意到:
MS Visual C++在处理"静态常量"变量时有一个错误认为有可用的补丁,或者您可以将其更改为#defines。从类的父目录进行操作,或将其添加到MATLAB中路径(例如,如果您解压缩到"myhome/@kde",则matlab中的cd为"myhome"dir,或将其添加到路径中。(".
我使用了其他编译器,如g++和gcc,但它仍然无法编译。
您的答案就在@kde/mex/makemex.m中(http://www.ics.uci.edu/~ihler/code/kde.tar.gz(。BallTree.cpp的构建命令是:
mex BallTree.cpp cpp/BallTreeClass.cc
注意,您还必须包含实现文件(cpp/BallTreeClass.cc(.
BallTree::createInMatlab(...)
定义在BallTreeClass.cc的第432行。
你可能只是想运行makemex.m,而不是自己去做。
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中