alecjacobson / gptoolbox

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

Error after using compiled mex files (CMake / VS 2015): Invalid MEX-file ... Function mexFunction is missing. #70

Closed oqilipo closed 5 years ago

oqilipo commented 6 years ago

I''ve created a project for the mex files with CMake 13.12.1 and build it with VS2015 (Win7). Everything worked fine without errors using Boost 1.67 and CGAL 4.12 and the latest version of libigl.

But when I try to test the compiled mex files I receive the following error:

mesh_boolean_example
Invalid MEX-file 'C:\dev\gptoolbox\mex\Debug\mesh_boolean.mexw64': Function mexFunction is missing.

Error in mesh_boolean_example (line 29)
[W,H] = mesh_boolean(Mesh(1).Vertices,Mesh(1).Faces,Mesh(2).Vertices,Mesh(2).Faces, 'union');

Any help is appreciated.

Thanks in advance

alecjacobson commented 6 years ago

huh. It might be missing the -DMEX flag. I've also updated the cmakelists.txt so this might be fixed now.

maxfrei750 commented 6 years ago

Setup:

I have the same problem. When I compile with Matlab 2017a I get: Function mexFunction is missing. When using Matlab 2018b I get: Gateway function is missing.

I think both errors are actually thrown due to the same reason, i.e. that the main-function of the mex-files is not correctly named (see here).

I already tried updating gptoolbox to the most recent version, but unfortunately that did not help.

What do you mean by

It might be missing the -DMEX flag.

?

Do you mean it is a CMake flag that should be set automatically and it would help to set it automatically? If so, then what kind of Flag is it? Boolean?

Thank you very much.

maxfrei750 commented 6 years ago

Perhaps this has something to do with the issue: https://github.com/DIPlib/diplib/issues/13 Unfortunately, I'm not familiar enough with your code and CMake in general to evaluate that myself.

alecjacobson commented 6 years ago

I've made a change in 0121b32 that might fix some of these issues. Could you please try cmake, make again?

maxfrei750 commented 6 years ago

Thanks for tackling the problem so fast. Unfortunately, the problem persists for both 2017a and 2018b.

alecjacobson commented 6 years ago

I'm not a windows user so this is difficult to debug. On Mac/linux I would check that the mexFunction symbol is compiled using:

 nm /usr/local/gptoolbox/mex/mesh_boolean.mexmaci64  | grep mexFunction

and see

0000000000022370 T _mexFunction

Is there a windows way to determine what symbols are ending up in the output?

maxfrei750 commented 6 years ago

VS2015 offers a tool called dumpbin.exe, which should provide what you are asking for. I attached the output of dumpbin /all C:\dev\gptoolbox\mex\mesh_boolean.mexw64. Unfortunately, mexFunction does not seem to occur.

output_dumpbin.txt

alecjacobson commented 6 years ago

Hmm, well this looks like it's not compiling anything in mesh_boolean.cpp. Are you sure you have the latest version? The first line should be:

include <igl/copyleft/cgal/mesh_boolean.h>

and not

ifdef MEX

maxfrei750 commented 6 years ago

I just freshly downloaded everything yesterday. The first line is indeed: #include <igl/copyleft/cgal/mesh_boolean.h>

alecjacobson commented 6 years ago

could you try deleting cmake/FindMATLAB.cmake and recreating the vs project from cmake?

On Tue, Nov 27, 2018 at 9:28 AM Max Frei notifications@github.com wrote:

I just freshly downloaded everything yesterday. The first line is indeed:

include <igl/copyleft/cgal/mesh_boolean.h>

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/alecjacobson/gptoolbox/issues/70#issuecomment-442077397, or mute the thread https://github.com/notifications/unsubscribe-auth/ACI0mR-ZtDxFccRnbl5UmqCDNjvcDn3qks5uzUwEgaJpZM4WFpjH .

maxfrei750 commented 6 years ago

Still the same error messages for 2017a as well as 2018a. I attached the new output of dumpbin. output_dumpbin.txt

oqilipo commented 6 years ago

Same here, after deleting the FindMATLAB.cmake

alecjacobson commented 6 years ago

I'm still thinking this is an error in the FindMATLAB. I checked in a new version 60ceec3 . Could you please try a fresh cmake?

oqilipo commented 6 years ago

Sorry, still the same error: Gateway function is missing. This time tested on another machine with Windows 10, VS 2017, CMake 3.13.0, Boost 1.68.0, CGAL 4.13, MATLAB 2018b.

alecjacobson commented 6 years ago

OK, we might need somebody with more VS experience. My guess is that this has something to do with the symbol "visibility" settings. MATLAB would like to have all symbols hidden except mexFunction. My current guess is that even this symbol is somehow being hidden.

maxfrei750 commented 6 years ago

By the way: What compilation preset do you recommend? I always used Release. Is that actually correct?

oqilipo commented 6 years ago

By the way: What compilation preset do you recommend? I always used Release. Is that actually correct?

@maxfrei750 I always try both release and debug, but release should be fine.

By the way, if you only need a specific function of the toolbox, you can try to build it in MATLAB. Check out the attached file: compile_mesh_boolean.zip This still works for me. Let me know if you have any questions.

alecjacobson commented 6 years ago

this could potentially be helpful. If the matlab mex command works, could you run it in verbose mode and send the full compilation command that it prints?

Then also send the compilation command that VS runs. We could compare the flags.

oqilipo commented 6 years ago

Here is the MATLAB log: mesh_boolean_compile_MATLAB.log This only works by replacing the two files assign_scalar.cpp & assign_scalar.h in ..\libigl\include\igl\copyleft\cgal with the files from the zip file.

The VS log will take some minutes.

alecjacobson commented 6 years ago

(How come you have to comment out those lines in assign_scalar.h? I thought the #ifndef WIN32 would stop them from being compiled on windows already).

alecjacobson commented 6 years ago

From looking at the log I'm guessing /EXPORT:mexFunction is the key flag that we need during linking. Let's see if the visual studio output has that present.

oqilipo commented 6 years ago

(How come you have to comment out those lines in assign_scalar.h? I thought the #ifndef WIN32 would stop them from being compiled on windows already).

Sorry, don't know. I reported it here: https://github.com/libigl/libigl/issues/693#issuecomment-388749827

oqilipo commented 6 years ago

From looking at the log I'm guessing /EXPORT:mexFunction is the key flag that we need during linking. Let's see if the visual studio output has that present.

Cmake 1st trial: gptoolbox_cmake_1trial.log

Cmake 2nd trial after disabling eltopo & embree: gptoolbox_cmake_2trial_after_disabling_eltopo_and_embree.log

Debug in VS2015: mesh_boolean_compile_VS2015.log

alecjacobson commented 6 years ago

OK, thanks. Can you try manually adding the /EXPORT:mexFunction flag in VS ?

oqilipo commented 6 years ago

A more detailed log of a release build: mesh_boolean_compile_VS2015_release_detailed.log

OK, thanks. Can you try manually adding the /EXPORT:mexFunction flag in VS ?

I will try.

oqilipo commented 6 years ago

OK, thanks. Can you try manually adding the /EXPORT:mexFunction flag in VS ?

Wow, that worked. I've added /EXPORT:mexFunction to: Properties -> Linker -> Command Line -> Additonal %(AdditionalOptions) /machine:x64 /EXPORT:mexFunction

Thanks a lot!

alecjacobson commented 6 years ago

Awesome. So now I need to figure out how to get this into the cmake...

oqilipo commented 6 years ago

Maybe this helps: https://stackoverflow.com/a/11095194 or http://matitk-cmake.blogspot.com/

alecjacobson commented 6 years ago

Thanks, could you give this new cmake a try ca64d68

oqilipo commented 6 years ago

Yes, works!

oqilipo commented 6 years ago

(How come you have to comment out those lines in assign_scalar.h? I thought the #ifndef WIN32 would stop them from being compiled on windows already).

Now this issue should not be very important anymore.

alecjacobson commented 6 years ago

great. @maxfrei750 want to also give it a try?

maxfrei750 commented 6 years ago

Finally had the time to test it... and it works! Very nice! Thanks you two!

maxfrei750 commented 5 years ago

@oqilipo I think we can close this issue.