Error using mex in matlab

Asked 1 years ago, Updated 1 years ago, 141 views

I am trying to run a script for matlab that was created more than 10 years ago.
There were some problems with the differences in version and functionality, but I think I managed to solve them.However, there are problems that cannot be resolved to the end.

I am having trouble calling the function of the file written in *cpp/*h from the matlab script.My understanding is that in order to call the cpp file from the matlab script (for example, AviReadMex.cpp), you need to use a function called mex.

So,

 mex AviReadMex.cpp


when I went to
The following error occurred:

Building with 'MinGW64 Compiler (C++)'.
Error using mex
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0xeb): undefined reference to
`CVideo::CVideo()'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0xff): undefined reference to
`CVideo::OpenVideo(char const*)'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x10c): undefined reference to
`CVideo::GetCodec()const'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x133)— undefined reference to
`CVideo::CloseVideo()'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x1a5)— undefined reference to
`CVideo::GetHeight()const'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x1b4)— undefined reference to
`CVideo::GetWidth()const'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x21b): undefined reference to
`CVideo::GetDataImage(unsigned char*, int)const'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x242)— undefined reference to
`CVideo::CloseVideo()'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x24b): undefined reference to
`CVideo::~CVideo()'
C:\Users\AKIHIR~1\AppData\Local\Temp\mex_156313621567061_1472\AviReadMex.obj: AviReadMex.cpp: (.text+0x259)— undefined reference to
`CVideo::~CVideo()'
collect2.exe:error:ld returned1 exit status

For AviReaderMex.cpp,

CVideo AviVideo;

There is a line like this, so I think this is the reason.

In the section to load the library in AviReaderMex.cpp, click

#include<mex.h>
# include "Video.h"
#define NUMBER_OF_FIELDS2

Yes.
Video.cpp and Video.h are also in the same folder as AviReaderMed.cpp.

By the way,

 mex Video.cpp

If the function in AviReaderMex.cpp is insufficient, an error will appear.

One question I have is that the folder is separate from "C:\Users\AKIHIR~1\AppData\Local\Temp", so I don't understand why this folder is loaded.

If anyone knows how to resolve the cause of the error, please let me know.

Your environment is
Operating System: Windows 10 Matlab version:R2017b
That's it.

Thank you for your cooperation.

c++ matlab

2022-09-30 19:56

1 Answers

MATLAB cannot directly invoke C/C++ functions.Therefore, you must create an interface function in C/C++ that follows MATLAB's conventions, such as data format conversion, between the C++ function you want to use and the MATLAB function to create a library for MATLAB.To create a library, you must have both a file containing the C++ function you want to use and a file containing the function of the interface.

In this case, AviReaderMex.cpp is the interface and Video.cpp wants to use some of the C++ functions.

If Video.cpp has all the functions you want to use

 mex AviReaderMex.cpp Video.cpp

So, I think it will work, but if you have any other functions or libraries you need, see what you need.

Also, in the command window,

doc mex

It is recommended that you type for help.


2022-09-30 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.