How to compile .mex from folders path?

I need to compile .mex files from path folder. Is there any command for that or any other process for compiling mex files. Below are the files
Suppose I need to use this function mex_pb_parts_final_selected in demo.m file and it gives me an error mex_pb_parts_final_selected function is not exist. Can someone guide me how I resolve this error? Thanks

2 Comments

These files are compiled already for MacOS computers. If they cannot be accessed from am M-file, either the folder i not included in the path, or you do not run Matlab on a Mac.
Hey Jan, I am using windows OS and main.m file I already includes these paths as below
addpath(genpath(('third_party/Tardif')));
addpath('third_party/BSR/grouping/lib');
addpath('mexFunctions');

Sign in to comment.

 Accepted Answer

Jan
Jan on 7 Feb 2023
Moved: Jan on 7 Feb 2023
@Gundeep: Prefer using absolute paths. If e.g. the folder "mexFunctions" is in the current folder, use:
addpath(fullfile(cd, 'mexFunctions'))
Maybe addpath() tries to o this automatically, but the explicit definition of the wanted folder is safer.
As I've written already, the mex files are compiled for MacOS and cannot be used under Windows. You need the source codes in C or C++ and compile them for Windows. If you do not find the sources or instructions for a compilation, you have to contact the authors.

22 Comments

@Jan: Means it is not possible to use mex file in windows and there are no source codes of C and C++ in that folder only mex files are present.
Mex files are specific to an architecture. That means you can't mix and match between Windows, MacOS, and Linux (you also can't mix 32 bit and 64 bit, which leads me to expect that native ARM compiled MacOS binaries will not work for Intel MacOS (while the reverse might be possible thanks to Rosetta 2), but that is conjecture from my side).
If the mex files do not exist, you will either have to create them yourself, or get someone else to create them for you.
If you don't have any source files available, that means you need to contact the original creators of the mex files you were provided.
@Gundeep: As said already, ask the authors of the code for help. Did you download the tool from a public location? Then posting a link would be a good idea, such that we can look for the source files also.
@Jan This is github repo link - Repo Link. I need to run this code for testing purpose.
OK, but why are you not answering the question about asking the authors? Did you ask them or not? If not, why not? They will know more about their code than you or us.
I mail to them but they're not responding, so I put my issue here.
@Gundeep: Thanks for this clarification. It is useful to mention such details in the question already.
@Jan Sorry for that, Is it possible to run that repo on windows?
@Gundeep: As you have explained already by your own, the sources are missing to compile the mex functions.
Means with this github repo, I can't able to run that code?
@Gundeep: As far as I can see, this link contains C sources for the mex functions. They are pre-compiled for Macs only. So try to compile them by your own. Hopefully you find exhaustive instructions in the documentation. All I can find is:
"The code is tested on Mac OS X El Capitan. If you want to use it on other platform, you need to compile the .mex files using the source code included."
I do not have more information than you have.
@Jan: Is there any way to compile mex files for windows?
It is a good habit to Google such questions before posting them.
You can use the mex function to compile the C source files to a mex file. See the documentation for examples. You will need a windows compiler. You can get one for free on the file exchange (you should get a link when you try to compile something).
I already googled @Rik, I guess you didn't read whole comments. That repo don't have C or C++ files. They only have .mex files in folders. That's why I put my doubt here.
Since Jan posted the link contains C source files, I was working under that assumption. You then asked whether it is possible to compile mex files for windows. A Google search 'compile mex windows matlab' should have turned up the documentation for the mex function.
If you look at the actual folder containing the concerned files, you may have noticed that the compiled binaries are from an external source. Based on the readme and the name, I presume you will need the resources on this page to get the original source.
I could not find a single-click compilation option, but there are some source files in there. Note that your computer may complain that you can't safely download/unpack the tgz file linked there, at least mine did.
You can find the source file in BSR\grouping\source\gpb_src\matlab\segmentation after unpacking.
@Rik: Hey, what I need to download from this page. I clicked on download files and nothing happened.
You may need to reduce your security settings, which is well beyond the scope of this forum. I just tried rightclicking and choosing 'save link as'. This showed a warning I could choose to ignore.
@Rik: Which link you want to save?
I was looking for source code, so "Source code (for Linux/Mac, 32/64 bits)" seemed to make sense to try.
@Rik: By clicking this "Source code (for Linux/Mac, 32/64 bits)" nothing happened.
I am not the administrator for that website nor for your computer, so I can't fix that for you. When I right-clicked that link and chose the 'save link as' option I was able to save the tgz file. If you are unable to do so, you will need to contact the administrator for that website, or your computer, or both.
@Gundeep: When I click on this link, the download starts directly. Unpacking fails due to missing rights to create symbolic links, but I assume unpacking with admin privileges will work. The file is too big to be posted here as attachment.
How to download a file from the web is not a Matlab problem.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 7 Feb 2023
Edited: Image Analyst on 7 Feb 2023
I don't understand. Like Jan said it looks like they have already been compiled into mex files. Do you want to compile your demo.m file that uses those .mex files? If so you might need to use the -a option in mcc or else just put the full path to them when you call loadlibrary in your .m file code.
If it says that it can't find mex_pb_parts_final_selected(), then that function is not in your demo.m file like you thought and it's not anywhere on the search path. Try putting it in the same folder as demo.m.

2 Comments

Hello, in the below path this function exist mex_pb_parts_final_selected() is located and demo.m file is located on another path. Can you guide me for this?
third_party/BSR/grouping/lib
Which DLL is mex_pb_parts_final_selected() trying to call?
Which DLL is for the Windows platform? You can't call a mex file made for a Mac.
Use the SetPath button on the Home tab of the tool ribbon and make sure you save the path, or make sure you call setpath() after you call setpath().

Sign in to comment.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2022b

Tags

Asked:

on 6 Feb 2023

Commented:

Jan
on 9 Feb 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!