error LNK2019: unresolved external symbol "public: __thiscall Matrix::Matrix(void)

4 visualizzazioni (ultimi 30 giorni)
I try to MEX a C++ file( with extension .cc) in MATLAB 2013b, compiler Visual Studio 2012 professional, OS 32-bit Windows, I take below errors ;
if true
correspondPixels.obj : error LNK2019: unresolved external symbol "public: __thiscall Matrix::Matrix(void)" (??0Matrix@@QAE@XZ) referenced in function _mexFunction
correspondPixels.obj : error LNK2019: unresolved external symbol "public: __thiscall Matrix::Matrix(int,int,double *)" (??0Matrix@@QAE@HHPAN@Z) referenced in function _mexFunction
correspondPixels.obj : error LNK2019: unresolved external symbol "public: __thiscall Matrix::~Matrix(void)" (??1Matrix@@QAE@XZ) referenced in function _mexFunction
correspondPixels.obj : error LNK2019: unresolved external symbol "public: int __thiscall Matrix::numel(void)const " (?numel@Matrix@@QBEHXZ) referenced in function _mexFunction
correspondPixels.obj : error LNK2019: unresolved external symbol "public: double * __thiscall Matrix::data(void)" (?data@Matrix@@QAEPANXZ) referenced in function _mexFunction
correspondPixels.obj : error LNK2019: unresolved external symbol "double __cdecl matchEdgeMaps(class Matrix const &,class Matrix const &,double,double,class Matrix &,class Matrix &)" (?matchEdgeMaps@@YANABVMatrix@@0NNAAV1@1@Z) referenced in function _mexFunction
correspondPixels.mexw32 : fatal error LNK1120: 6 unresolved externals
C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Link of 'correspondPixels.mexw32' failed
end
I searched similar errors and try to apply some advising solutions but no-one helps me. Maybe there is an declared constructor but undefined function or unimplemented ones? Maybe due to a missing .dll file? I am familiar with MATLAB more. not much C++. Is there any solution idea?

Risposte (2)

Walter Roberson
Walter Roberson il 13 Mar 2017
Class Matrix is not a standard C++ class; it is also not part of the common add-on "Boost".
Possibly it is derived from the book Vectors, Matrices and C++ Code by Sergio Pissanetzky

doner_t
doner_t il 13 Mar 2017
Thank you Walter. So due to the Class Matrix is not a standard C++ class, should I create some .dll or .lib and maybe .h files using MATLAB compiler, like doing here ?
Regards,
Here is a part of very large Matrix.cc
...
Matrix::Matrix ()
{
_alloc(0,0,undef);
}
Matrix::Matrix (int sz, FillType type)
{
sz = std::max(0,sz);
_alloc(sz,sz,type);
}
Matrix::Matrix (int rows, int cols, FillType type)
{
rows = std::max(0,rows);
cols = std::max(0,cols);
_alloc(rows,cols,type);
}
Matrix::Matrix (const Matrix& that)
{
_alloc(that._rows,that._cols,undef);
*this = that;
}
Matrix::Matrix (int rows, int cols, double* data)
{
_rows = std::max(0,rows);
_cols = std::max(0,cols);
_data = data;
_wrapped = true;
}
Matrix::~Matrix ()
{
_delete();
}
...
And here again a part is Matrix.hh
...
// construct empty matrix
Matrix ();
//Matrix::Matrix(void);
// construct square matrix with specified fill
Matrix (int sz, FillType type = zeros);
// construct matrix with specified fill
Matrix (int rows, int cols, FillType type = zeros);
// copy constructor
Matrix (const Matrix& that);
// create a wrapped matrix
// (i.e. we're not responsible for freeing the data)
Matrix (int rows, int cols, double* data);
// destructor
~Matrix ();
...
And here is whole correspondPixels.cc
#include <string.h>
#include <mex.h>
#include "Matrix.hh"
#include "csa.hh"
#include "match.hh"
extern "C" {
static const double maxDistDefault = 0.0075;
static const double outlierCostDefault = 100;
void
mexFunction (
int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[])
{
// check number of arguments
if (nlhs < 2) {
mexErrMsgTxt("Too few output arguments.");
}
if (nlhs > 4) {
mexErrMsgTxt("Too many output arguments.");
}
if (nrhs < 2) {
mexErrMsgTxt("Too few input arguments.");
}
if (nrhs > 4) {
mexErrMsgTxt("Too many input arguments.");
}
// get arguments
double* bmap1 = mxGetPr(prhs[0]);
double* bmap2 = mxGetPr(prhs[1]);
const double maxDist =
(nrhs>2) ? mxGetScalar(prhs[2]) : maxDistDefault;
const double outlierCost =
(nrhs>3) ? mxGetScalar(prhs[3]) : outlierCostDefault;
// check arguments
if (mxGetM(prhs[0]) != mxGetM(prhs[1])
|| mxGetN(prhs[0]) != mxGetN(prhs[1])) {
mexErrMsgTxt("bmap1 and bmap2 must be the same size");
}
if (maxDist < 0) {
mexErrMsgTxt("maxDist must be >= 0");
}
if (outlierCost <= 1) {
mexErrMsgTxt("outlierCost must be >1");
}
// do the computation
const int rows = mxGetM(prhs[0]);
const int cols = mxGetN(prhs[0]);
const double idiag = sqrt( (double)(rows*rows + cols*cols));
const double oc = outlierCost*maxDist*idiag;
Matrix m1, m2;
const double cost = matchEdgeMaps(
Matrix(rows,cols,bmap1), Matrix(rows,cols,bmap2),
maxDist*idiag, oc,
m1, m2);
// set output arguments
plhs[0] = mxCreateDoubleMatrix(rows, cols, mxREAL);
plhs[1] = mxCreateDoubleMatrix(rows, cols, mxREAL);
double* match1 = mxGetPr(plhs[0]);
double* match2 = mxGetPr(plhs[1]);
memcpy(match1,m1.data(),m1.numel()*sizeof(double));
memcpy(match2,m2.data(),m2.numel()*sizeof(double));
if (nlhs > 2) { plhs[2] = mxCreateDoubleScalar(cost); }
if (nlhs > 3) { plhs[3] = mxCreateDoubleScalar(oc); }
}
}; // extern "C"
  2 Commenti
Walter Roberson
Walter Roberson il 13 Mar 2017
You could probably just mex everything together, but more common would be to compile the Matrix stuff into a shared library and use a -l switch on the mex command line to link in the library.
doner_t
doner_t il 14 Mar 2017
There is such an build.m file: I think that it try to mex files all together as you said.
%mex -v CXXFLAGS="\$CXXFLAGS -O3 -DNOBLAS" correspondPixels.cc csa.cc kofn.cc match.cc Exception.cc Matrix.cc Random.cc String.cc Timer.cc
mex -v CXXFLAGS="\$CXXFLAGS -O3 -DNOBLAS" correspondPixels.cc csa.cc kofn.cc match.cc Exception.cc Matrix.cc Random.cc String.cc
When I directly run the above build.m file, returns some errors about the Matrix.hh and Random.hh seen below:
Error using mex
Matrix.cc
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(65) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(65) : error
C2146: syntax error : missing ';' before identifier 'u_int32_max'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(65) : error
C2143: syntax error : missing ';' before '='
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(65) : error
C2238: unexpected token(s) preceding ';'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(72) : error
C2061: syntax error : identifier 'u_int64_t'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(72) : error
C2535: 'Random::Random(void)' : member function already defined or declared
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(68) : see
declaration of 'Random::Random'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(82) : error
C2061: syntax error : identifier 'u_int64_t'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(93) : error
C2146: syntax error : missing ';' before identifier 'ui32'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(93) : error
C2433: 'Random::u_int32_t' : 'inline' not permitted on data declarations
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(93) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(93) : warning
C4183: 'ui32': missing return type; assumed to be a member function returning 'int'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : error
C2146: syntax error : missing ';' before identifier 'ui32'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : error
C2433: 'Random::u_int32_t' : 'inline' not permitted on data declarations
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : error
C2061: syntax error : identifier 'u_int32_t'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : error
C2535: 'int Random::ui32(void)' : member function already defined or declared
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(93) : see
declaration of 'Random::ui32'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(94) : warning
C4183: 'ui32': missing return type; assumed to be a member function returning 'int'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(98) : error
C2061: syntax error : identifier 'u_int64_t'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(101) : error
C2146: syntax error : missing ';' before identifier '_seed'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(101) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(104) : error
C2146: syntax error : missing ';' before identifier '_xsubi'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(104) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(109) : error
C2143: syntax error : missing ';' before 'Random::ui32'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(109) : error
C2433: 'u_int32_t' : 'inline' not permitted on data declarations
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(109) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(110) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(111) : error
C2065: 'u_int32_max' : undeclared identifier
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(111) : error
C2660: 'Random::ui32' : function does not take 2 arguments
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2143: syntax error : missing ';' before 'Random::ui32'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2433: 'u_int32_t' : 'inline' not permitted on data declarations
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2086: 'int u_int32_t' : redefinition
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(109) :
see declaration of 'u_int32_t'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2146: syntax error : missing ')' before identifier 'a'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2761: 'int Random::ui32(void)' : member function redeclaration not allowed
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(115) : error
C2059: syntax error : ')'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(116) : error
C2143: syntax error : missing ';' before '{'
c:\users\downloads\deneme_bench_nok\deneme\bench\source\Random.hh(116) : error
C2447: '{' : missing function header (old-style formal list?)
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) : error
C2146: syntax error : missing ';' before identifier '_qnan'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) : warning
C4305: 'initializing' : truncation from '__int64' to 'int'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) : warning
C4309: 'initializing' : truncation of constant value
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(115) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(115) : error
C2146: syntax error : missing ';' before identifier '_snan'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(115) : error
C2086: 'const int u_int64_t' : redefinition
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) :
see declaration of 'u_int64_t'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(115) : warning
C4305: 'initializing' : truncation from '__int64' to 'int'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(115) : warning
C4309: 'initializing' : truncation of constant value
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(116) : error
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(116) : error
C2146: syntax error : missing ';' before identifier '_inf'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(116) : error
C2086: 'const int u_int64_t' : redefinition
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(114) :
see declaration of 'u_int64_t'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(116) : warning
C4305: 'initializing' : truncation from '__int64' to 'int'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(116) : warning
C4309: 'initializing' : truncation of constant value
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(127) : warning
C4273: 'rint' : inconsistent dll linkage
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(515) : see
previous definition of 'rint'
C:\Users\Downloads\deneme_Bench_NOK\deneme\bench\source\Matrix.cc(142) : warning
C4273: 'log2' : inconsistent dll linkage
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(504) : see
previous definition of 'log2'

Accedi per commentare.

Categorie

Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by