Has the MEX function (mxGetComplexDoubles) been deprecated in R2024b?
68 views (last 30 days)
Show older comments
I am preparing a MEX file that includes the function: (mxGetComplexDoubles).
I tried to compile and link it to get the executable file (*. mexw64) corresponding to the source file: (*.F) using either of the following commands:
mex -R2018a filename.F
mex -R2018a -I"C:\Program Files\MATLAB\R2024b\extern\include" -L"C:\Program Files\MATLAB\R2024b\extern\lib\win64\microsoft" -llibmex -llibmx filename.F
The compilation was successful; however, the linking was not because:
unresolved external symbol mxgetcomplexdoubles800
This happened despite my file containing the command (mxGetComplexDoubles) rather than the command (mxGetComplexDoubles800).
Surprisingly, upon searching for (mxGetComplexDoubles), I found that it is not there in:
"C:\Program Files\MATLAB\R2024b\bin\win64\libmex.dll"
"C:\Program Files\MATLAB\R2024b\bin\win64\libmat.dll"
My questions:
- Has the function (mxGetComplexDoubles) been deprecated in R2024b?
- What should I do in that case?
6 Comments
dpb
on 6 Apr 2025
Edited: dpb
on 6 Apr 2025
I guess i misread the meaning of the initial -- i thought you were using complex variables but not the interleaved interface...
I don't have R2024 installed, but in R2021b that I do have, mxGetComplexDoubles is in libmix.lib as expected, however, the exported symbols are
"MXGETCOMPLEXDOUBLES800"
"__imp_MXGETCOMPLEXDOUBLES800"
"__imp_mxGetComplexDoubles_800"
"mxGetComplexDoubles_800"
The error you got of
unresolved external symbol mxgetcomplexdoubles800
would be expected result because Fortran by default generates all uppercase symbol names as is shown above...the "800" comes because the compiler automagically adds the number of argument bytes onto the symbol name unless a compiler switch is set expressly to not do so.
Now, why it's apparently creating the lowercase name rather than expected uppercase I dunno...but that looks to me to be the issue.
It's been a long time since I messed with details of libraries; I recalled I thought that the MS lib utility would export a list of the library symbols, but I couldn't get the version installed here now with VS to do so...I ended up grep-ing the lib file for the case-insensitive symbol name and then parsing it down to the specific ones of interest--a lot of work for what should be a trivial exercise. But, you can grep or otherwise do a text search inside the libmx.lib library file for the symbol string and you should find, I expect, the same result.
ADDENDUM
Indeed, it had been a really long time...the utility is nm.exe, not the lib command...it creates a really long list, but if you have installed mingw64, it is installed automatically as one of the developer tools.
nm -g -U -W libmx.lib >mxlib.lst
will give you a (very long) text file mxlib.lst that you can search for the specific symbol name...the result will look something like
C:\MLR2021b\extern\lib\win64\microsoft>grep -i -A4 -B1 mxgetcomplexdouble mxlib.lst
.text
__imp_MXGETCOMPLEXDOUBLES800
MXGETCOMPLEXDOUBLES800
.idata$4
.idata$5
.idata$6
.text
--
.text
__imp_mxGetComplexDoubles_800
mxGetComplexDoubles_800
.idata$4
.idata$5
.idata$6
.text
C:\MLR2021b\extern\lib\win64\microsoft>
Answers (1)
Walter Roberson
on 6 Apr 2025
Edited: Walter Roberson
on 6 Apr 2025
No, mxGetComplexDoubles has not been deprecated in R2024b.
The problem is you called it from Fortran and Fortran is calling the name in all lower-case.
You can add a C function named mxgetcomplexdoubles800 that does nothing but call mxGetComplexDoubles_800
Or you can use BIND on the Fortran code side; https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-0/bind-c.html (requires Fortran 2003 or later)
9 Comments
dpb
on 1 May 2025 at 19:37
Edited: dpb
on 4 May 2025 at 19:48
@Magdy Hanna, you've still not told us which Fortran compiler you're trying to use.
It would be most helpful to see the result of
mex -setup
and then also the output of recompiling with the "-v" option.
The mismatch in naming conventions indicates something is not correct in the setup or the choice of libraries or there is a bug in the distribution libraries in not being built to match the installed compiler.
One may be able to force the naming convention mismatch to go away with BIND, but I'd have little confidence without knowing the above details it will actually link correctly.
dpb
on 3 May 2025 at 12:36
Edited: dpb
on 4 May 2025 at 19:47
"Or you can use BIND on the Fortran code side;..."
The definition of "interoperable" from the Fortran Standard technical terms is:
"interoperable (15.2) : The property of a Fortran entity that ensures that an equivalent entity may be defined by means of C."
Section 15.2 states
15.2 Interoperability between Fortran and C entities
The following subclauses define the conditions under which a Fortran entity is interoperable. If a Fortran entity is interoperable, an equivalent entity may be defined by means of C and the Fortran entity is said to be interoperable with the C entity. There does not have to be such an interoperating C entity. [emphasis added-dpb]
So, while the Standard defines the syntax of Fortran that will produce a matching interface to C, it does not specify the implementation or that there necessarily will even be one. The implementation is left to the developer and binding is still dependent upon there being a conforming C compiler. It's far more than just changing the name, BIND() also changes the calling conventions from those used in Fortran to those of C.
While the Standard doesn't require a conforming Fortran compiler vendor to produce a companion C compiler, both Intel and gfortran do have at least one. Unlike IntelOneAPI, gfortran is not a full Fortran compiler but a front end to gcc, so it comes along for the ride.
I'm still convinced @Magdy Hanna is using one Fortran compiler and trying to link against libraries built with a different and non-conforming one but unless and until is willing to provide the additional missing information, not much else to be done but to point out the issue.
See Also
Categories
Find more on Fortran with MATLAB 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!