How do I convert to Mex from Cpp using Xcode ver 10
Mostra commenti meno recenti
For Mac Users, I need that info. Thanks
14 Commenti
Geoff Hayes
il 18 Giu 2019
Stelios - what do you want to convert from C++ to Mex? A single file/program? Several files? Please provide some context.
Geoff Hayes
il 18 Giu 2019
This question seems identical to your last one: https://www.mathworks.com/matlabcentral/answers/467491-cpp-to-mex-conversion.
Stelios Fanourakis
il 18 Giu 2019
Geoff Hayes
il 18 Giu 2019
It looks like it has been written as a mex function so I'm not all that clear on your question. Did you write the above? Or is the problem that you are trying to compile the above in MATLAB on your Mac? Please clarify.
Stelios Fanourakis
il 18 Giu 2019
Modificato: Stelios Fanourakis
il 18 Giu 2019
Stelios Fanourakis
il 18 Giu 2019
Walter Roberson
il 18 Giu 2019
Your code has
const int *DimsBness;
That is incorrect code on 64 bit systems. It should be
const mwSize *DimsBness;
Stelios Fanourakis
il 18 Giu 2019
Walter Roberson
il 18 Giu 2019
MATLAB for 64 bit Mac was introduced in R2009b. R2010a was the last MATLAB release for 32 bit Mac. Therefore if you are running with R2010b or later on Mac, you are definitely using 64 bit version.
The official change to the API was added in R2006b https://www.mathworks.com/matlabcentral/answers/99144-how-do-i-update-mex-files-to-use-the-large-array-handling-api-largearraydims -- from then on mwSize should have been used instead of a hard-coded int data type.
If you wish to double-check then,
>> computer
ans =
'MACI64'
Notice the "64"
The C++ standard defines "int" as being "at least" 16 bits wide. https://en.cppreference.com/w/cpp/language/types . Using "int" to store the length of an array can in theory restrict the array to no more than 65535 long along any dimension. On systems that happen to use 32 bit int, using int for the size would restrict the array to 2 gigabytes (unsigned int would have at least gotten you to 4 gigabytes.)
Stelios Fanourakis
il 19 Giu 2019
Walter Roberson
il 19 Giu 2019
You should not use -compatibleArrayDims
"I was getting the error message that I needed to update my Xcode compiler in order to utilize the new API,"
What were the error messages? Just about every mex compilation these days gives a warning message to stop using -compatibleArrayDims and rewrite code to use mwSize, but that is not an error message.
"However, it seems that I cannot do anything with it, since I cannot open it or run it."
-compatibleArrayDims is only for use on 32 bit systems.
"I cannot even upload it here since the Mathworks platform does not accept the extension .mexmaci64 "
You can zip any file and upload the zip if it is small enough. However I doubt we need the file.
"I need to setup this Xcode app to export as .m files and not .mexmaci64."
If you need that, then you are using the wrong software product. There is no known C++ to MATLAB convertor.
C++ code compiled to .mexmaci64 is directly callable from MATLAB by giving the function name, just as if it were a built-in MATLAB function.
Stelios Fanourakis
il 19 Giu 2019
Modificato: Stelios Fanourakis
il 19 Giu 2019
Rik
il 19 Giu 2019
With example.mexmaci64 you can use example('input') from inside Matlab (assuming that your function takes such an input).
Stelios Fanourakis
il 20 Giu 2019
Risposta accettata
Più risposte (1)
Wow, what an inefficient communication.
As Walter has said already, the line
const int *DimsBness;
must be changed to
const mwSize *DimsBness;
This might matter other variables of the type int also.
C++ Mex files are compiled to mexmaci64 files. Of course you can neither edit these output files, not run it directly. This is the nature of compiled files. Simply put this file to a folder, which is included to your Matlab path and call it like any other function stored in an M-file:
result = BoneSegmentationDP(args)
where args are the 5 needed inputs.
"I was getting the error message that I needed to update my Xcode compiler in order to utilize the new API, that's why I used mex -compatibleArrayDims BoneSegmentationDP.cpp"
No. If you get the message, that the Xcode compiler needs an update, update the Xcode compiler. It is off-track to play around with the compatibleArrayDims flag.
8 Commenti
Stelios Fanourakis
il 19 Giu 2019
Modificato: Walter Roberson
il 20 Giu 2019
Stelios Fanourakis
il 20 Giu 2019
Stelios Fanourakis
il 20 Giu 2019
Modificato: Walter Roberson
il 20 Giu 2019
Walter Roberson
il 20 Giu 2019
What leads you to think that you need to upgrade your XCode itself? The link you gave does not mention anything about that.
There was a time when XCode only supported 32 bit Executables. The XCode for Snow Leopard (OS-X 10.6, 2009) and later have supported 64 bit executables. You are using an XCode that is at least 8 years newer than that, and your XCode defaults to 64 bit.
Stelios Fanourakis
il 23 Giu 2019
Walter Roberson
il 23 Giu 2019
Everyone gets that warning. It has nothing to do with you using Mac or any particular xcode version.
Walter Roberson
il 23 Giu 2019
mwSize is size_t which is unsigned long long for your system. It causes 8 bytes to be reserved for each variable that is to store an array size. That permits arrays larger than 2 gigabytes. Your existing use of int for the size is reserving only 4 bytes for array sizes.
Now you might be thinking that your particular use never involves arrays 2 gb or larger and you might be thinking that means that you do not need to use the larger variable. However 8 bytes is what matlab uses internally now and when matlab builds its internal description of the parameters to the call it is going to allocate memory based on the larger size. If your code were to try to use the sizes as if only 32 bits were allocated for the size then you would be looking for the second dimension size at the wrong place in memory.
Walter Roberson
il 23 Giu 2019
"Where do I replace them? In the C++ code?"
Yes. Edit the darn C++ code.
Categorie
Scopri di più su C Shared Library Integration in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!