Why Can't I build a C++ file using mex?
Show older comments
I have a C++ file that I want to use with my matlab code. The file compiles using mex successfully when I use
mex -c Miguel_2D_unwrapper.cpp
But fails when I use
mex Miguel_2D_unwrapper.cpp
I get the following error:
Error using mex
Cannot export mexFunction: symbol not defined
collect2.exe: error: ld returned 1 exit status
I am sure the problem is not with the code. I am using MinGW and matlab 2017a
2 Comments
Azuwien aida Bohari
on 28 Feb 2018
hi, me to experience the same error. i can compile imnov.c and mex complete successfully but fails when i want to compile comp.c and i get the same error.
Error using mex
Cannot export mexFunction: symbol not defined
collect2.exe: error: ld returned 1 exit status
can someone help me
Hamza Mahdi
on 28 Feb 2018
Answers (1)
Jan
on 22 Jun 2017
2 votes
Does the file contain the mexFunction() ? The error message tells clearly, that it doesn't.
5 Comments
Hamza Mahdi
on 22 Jun 2017
Edited: Hamza Mahdi
on 22 Jun 2017
Jan
on 22 Jun 2017
mex Miguel_2D_unwrapper.cpp tries to compile the file to a Mex file, which is a DLL called from Matlab. The entry point of this call is the function mexFunction(), which must be included in every Mex file. It is equivalent to the main() function in a stand-alone executable.
To solve your problem, you have to explain what your cpp file contains and what it should do. From where do you want to call it? I cannot decide if you have a Mex function, but you have to know this. Anyway, if you want to complile it by mex, you need a mexFunction.
The documentation of mex and the examples in matlabroot\extern\examples\ clarify the details.
Hamza Mahdi
on 22 Jun 2017
sana3 sal
on 22 May 2018
Edited: Walter Roberson
on 23 May 2018
Hello there, could you please help me by mentioning where i have to but the mexFunction() ? which file? which diectory?
i have this problem when i ran vl_compilenn command to configure the MatConvNet library :
>> vl_compilenn
Building with 'MinGW64 Compiler (C++)'.
Error using mex
Cannot export mexFunction: symbol not defined
Cannot export mexfilerequiredapiversion: symbol not defined
collect2.exe: error: ld returned 1 exit status
Error in vl_compilenn>mex_compile (line 585)
mex(args{:}) ;
Error in vl_compilenn (line 493)
mex_compile(opts, srcs{i}, objfile, flags) ;
Bharath Swaminathan
on 4 Sep 2023
Check out:
and:
https://in.mathworks.com/help/matlab/matlab_external/structure-of-c-mex-function.html
Categories
Find more on MATLAB Compiler 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!