Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oqilipo opened this issue Aug 21, 2018 · 34 comments

Comments

@oqilipo
Copy link
Contributor

oqilipo commented Aug 21, 2018

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
Copy link
Owner

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

@maxfrei750
Copy link
Contributor

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
Copy link
Contributor

maxfrei750 commented Nov 26, 2018

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

@alecjacobson
Copy link
Owner

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

@maxfrei750
Copy link
Contributor

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

@alecjacobson
Copy link
Owner

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
Copy link
Contributor

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
Copy link
Owner

alecjacobson commented Nov 27, 2018 via email

@maxfrei750
Copy link
Contributor

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

@alecjacobson
Copy link
Owner

alecjacobson commented Nov 27, 2018 via email

@maxfrei750
Copy link
Contributor

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

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 27, 2018

Same here, after deleting the FindMATLAB.cmake

@alecjacobson
Copy link
Owner

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
Copy link
Contributor Author

oqilipo commented Nov 27, 2018

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
Copy link
Owner

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
Copy link
Contributor

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

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

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
Copy link
Owner

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
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

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
Copy link
Owner

(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
Copy link
Owner

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
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

(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: libigl/libigl#693 (comment)

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

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
Copy link
Owner

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

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

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
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

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
Copy link
Owner

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

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

@alecjacobson
Copy link
Owner

Thanks, could you give this new cmake a try ca64d68

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

Yes, works!

@oqilipo
Copy link
Contributor Author

oqilipo commented Nov 28, 2018

(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
Copy link
Owner

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

@maxfrei750
Copy link
Contributor

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

@maxfrei750
Copy link
Contributor

maxfrei750 commented Nov 29, 2018

@oqilipo I think we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants