alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
629 stars 169 forks source link

Invalid MEX file #87

Open mishaelnuh opened 5 years ago

mishaelnuh commented 5 years ago

I'm trying to use a few MEX functions, but am running into an error in MATLAB saying XXX.mexw64 is not a valid Win32 application. This happens with most of the functions needing CGAL, everything else seems to be fine. Followed the instructions below:

Ok, did you already download CMake and VS2015?

  1. Open CMake-Gui.
  2. Set "Where is the sourcecode" to ./gptoolbox/mex and "Where to build the binaries" to ./gptoolbox/mex/build.
  3. Click on configure.
  4. A window opens. Select "Visual Studio 14 2015 Win64" for "Specify the generator for this project". Click "Finish" in the same window.
  5. Process the error messages CMake might throw and select the features you want for your build by checking/unchecking the associated checkboxes (e.g. WITH_ELTOPO).
  6. Click on configure again. If there are still error messages, then fix them. Repeat until there are no more error messages.
  7. Click on generate. There should be no error messages. If there are errors... fix them. :-)
  8. Click on open project, which opens the project in VS2015.
  9. In VS: Compile the project.

Originally posted by @maxfrei750 in https://github.com/alecjacobson/gptoolbox/issues/78#issuecomment-441975232

Configuration:

Any help would be much appreciated!

maxfrei750 commented 5 years ago

Do you use the 64- or the 32-bit version of Matlab? If you use the 32-bit version, then I would guess that you need to compile the mex file as 32-bit version as well, by selecting a different compiler in step 4.

mishaelnuh commented 5 years ago

I’m using a 64-bit version of Matlab.

maxfrei750 commented 5 years ago

Ok, then unfortunately, I don't think I can help you. I think I have seen this error before. However, I don't recall how or even if I solved it, since I moved away from Matlab for quite some time now. Perhaps @alecjacobson can help.

oqilipo commented 5 years ago

Did you build cgal in x64?

mishaelnuh commented 5 years ago

I've left cmake to download cgal and the precompiled binaries. I'm not too familiar with cmake, but I'm assuming it all gets compiled at the same time along with the rest of the solution? I've set Visual Studio to compile in x64.

oqilipo commented 5 years ago

I think you have to build cgal first: https://www.cgal.org/download/windows.html

mishaelnuh commented 5 years ago

Couldn't get it to work in the end. Switched to working on a Mac and it compiled without any issues.

Thanks for all the help!

alecjacobson commented 4 years ago

I don't work on Windows but some students have successfully got this to compile. @rarora7777 maybe you have a tip?

rarora7777 commented 4 years ago

I looked at my compile notes from a couple of months ago, and I had to do the following for CGAL.

tl;dr The main issue is that gptoolbox forces gmp, but I've only ever been able to use CGAL with mpir on my machines.

alecjacobson commented 4 years ago

If it works with mpir, do think we can automate using mpir instead of gmp on Windows within the cmake?

rarora7777 commented 4 years ago

I can confirm that it also works with gmp. But I still had to make a couple of manual changes.

jbHu67 commented 3 years ago

@rarora7777 I used MINGW and CMake 3.20.5 to compile the /mex on Windows 10. The 'Configure' and 'Generate' in Cmake were both successful finally, but when I used 'make' of Mingw to make them ,the errors in the following picture occured. Do you know why? Can you help me , please. Thank you very much.

error

rarora7777 commented 3 years ago

@babydu12138 I'm not even sure if MinGW is supported. I believe @alecjacobson has only ever built it for MSVC on Windows. Is it possible for you to switch to MSVC?

alecjacobson commented 3 years ago

I have never built gptoolbox on windows personally.

jbHu67 commented 3 years ago

@babydu12138 I'm not even sure if MinGW is supported. I believe @alecjacobson has only ever built it for MSVC on Windows. Is it possible for you to switch to MSVC?

Okay, I'll try it.

jbHu67 commented 3 years ago

@babydu12138 I'm not even sure if MinGW is supported. I believe @alecjacobson has only ever built it for MSVC on Windows. Is it possible for you to switch to MSVC?

Okay, I'll try it.

@rarora7777 I have Configured and generated the codes in mex with CMake sucessfully, but I don't know what should I do the next step, please tell me, thank you very much.

rarora7777 commented 3 years ago

Great! Now you just need to copy all the executables to the base folder, as that's where MATLAB requires them to be. That is, copy or move all mexw64 files from gptoolbox/mex/build/Release to gptoolbox/mex.

In addition, you need the dynamic library dependencies. Copy libgmp-10.dll and libgmp-4.dll from gptoolbox/mex/external/libigl/external/gmp/lib to gptoolbox/mex.

jbHu67 commented 3 years ago

Great! Now you just need to copy all the executables to the base folder, as that's where MATLAB requires them to be. That is, copy or move all mexw64 files from gptoolbox/mex/build/Release to gptoolbox/mex.

In addition, you need the dynamic library dependencies. Copy libgmp-10.dll and libgmp-4.dll from gptoolbox/mex/external/libigl/external/gmp/lib to gptoolbox/mex.

Thank you very much! I have compiled them successfully!

HoBool commented 3 years ago

Great! Now you just need to copy all the executables to the base folder, as that's where MATLAB requires them to be. That is, copy or move all mexw64 files from gptoolbox/mex/build/Release to gptoolbox/mex.

In addition, you need the dynamic library dependencies. Copy libgmp-10.dll and libgmp-4.dll from gptoolbox/mex/external/libigl/external/gmp/lib to gptoolbox/mex.

I copyed the "libgmp-10.dll" and "libgmp-10.lib" from "gptoolbox/mex/external/libigl/external/gmp/lib" and "libmpfr-4.dll" and "libmpfr-4.lib" from "gptoolbox/mex/external/libigl/external/mpfr/lib". It works.