Weird error on mex compilation
Show older comments
Hello Everybody,
before I get started let me please tell you that I do not know much about c++ programming so in case you answer to my question I would like to ask you kindly to make it as idiot-proof as possible :)
I would like to compile some third party software to control a camera. The code compilation works fine without errors when I do it using MS Visual Studio 2010. However, I get an error when I compile the same code (with the mex-related adjustments) using MATLAB (2015A, 64Bit) and I cannot make any sense of the error.
I attached a very basic example that illustrates the problem. I am including all required libraries necessary to create a object of the class PvDeviceSerial. The libs are provided by producer of the camera.
#include <mex.h.>
#include <stdio.h>
#include <PvDevice.h>
#include <PvDeviceSerialPort.h>
#include <PvDeviceAdapter.h>
void mexFunction(){
PvDeviceSerialPort lPort;
}
Using the following compilation command:
filename = '$PATH_TO_SOURCE\test.cpp';
mex('-IC:\Program Files (x86)\Pleora Technologies Inc\eBUS SDK\Includes',...
'-LC:\Program Files (x86)\Pleora Technologies Inc\eBUS SDK\Libraries',...
filename, '-v');
I get the following error:
Error using mex
Creating library test.lib and object test.exp
test.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl
PvDeviceSerialPort::~PvDeviceSerialPort(void)" (??1PvDeviceSerialPort@@UEAA@XZ) referenced in function "void
__cdecl mexFunction(void)" (?mexFunction@@YAXXZ)
test.obj : error LNK2019: unresolved external symbol "public: __cdecl PvDeviceSerialPort::PvDeviceSerialPort(void)"
(??0PvDeviceSerialPort@@QEAA@XZ) referenced in function "void __cdecl mexFunction(void)" (?mexFunction@@YAXXZ)
test.mexw64 : fatal error LNK1120: 2 unresolved externals
Compiling the same program in MS VS works fine (exactly the same code, except that "void mexFunction" is replaced my "int main").
I think it may be due to some compiler flags or something like that. I would highly appreaciate any comment on this as I am starting to get desperate. I included the header file with the class declaration. Maybe that helps.
Thanks a lot, Thomas
Answers (1)
James Tursa
on 26 Jul 2016
Edited: James Tursa
on 26 Jul 2016
First, get your mexFunction signature correct and try compiling again. Then we can work on other errors. So first change this:
#include <mex.h.>
:
void mexFunction(){
to this:
#include "mex.h"
:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
And re-compile.
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!