juliamatlab / mexjulia

embedding Julia in the MATLAB process.
MIT License
52 stars 14 forks source link

Executing Jl.build command fails #31

Closed yahyakp closed 7 years ago

yahyakp commented 7 years ago

Running jl.build gives the following error:

Error using jl.build (line 224) Mex build failed. Consider editing the 'build_*' fields in the mexjulia dictionary using the 'jl.set' command. Run 'jl.get' to see the current contents of the mexjulia dictionary. Running jl.get gives also a struct with no fields!

Any help would be highly appreciated.

twadleigh commented 7 years ago

Try running jl.config first.

On Nov 1, 2016 7:45 PM, "yahyakp" notifications@github.com wrote:

Running jl.build gives the following error:

Error using jl.build (line 224) Mex build failed. Consider editing the 'build_*' fields in the mexjulia dictionary using the 'jl.set' command. Run 'jl.get' to see the current contents of the mexjulia dictionary. Running jl.get gives also a struct with no fields!

Any help would be highly appreciated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/twadleigh/mexjulia/issues/31, or mute the thread https://github.com/notifications/unsubscribe-auth/ABf4bjERmXD89PdbWqVIV_9Jr7GOR5Omks5q5_ksgaJpZM4KmzY3 .

laughingrice commented 7 years ago

I'm running into the same issue, managed to get jl.config and jl.build to finally work after some changes, seems to work fine with a cursory test

(1) this fails cmd = 'println(Base.JLOptions().debug_level > 1)'; [~, dbg] = system(sprintf('"%s" -e "%s"', exe, cmd)); dbg = jl.chomp(dbg); jl.set('is_debug', dbg);

Looking at Base.JLOptions() in Julia, it indeed does not have the debug_level field. I commented it out and set dbg to 0 and managed to get passed that. Also dbg = jl.chomp(dbg); is incorrect even if it worked as it sets dbg to a string which always evaluates to true in the next tests even if it's zero.

(2) It later gets stuck on line 215 on the compile command. There seems to be an issue with the quotes, changing mex_ptrn to this worked (I have some spaces in the file names)

mex_ptrn = 'mex -largeArrayDims -outdir "%s" %s %s "%s" %s';

(3) Julia doesn't seem to include libopenlibm.dll.a (only the dll, not the lib)

Removing it from the list on line 172 finally allows things to compile

hope that helps

twadleigh commented 7 years ago

@laughingrice what is your Julia version? Pre 0.5, I suspect. You might try upgrading and trying again.

huytran216 commented 7 years ago

I am running into the same issue as laughingrice said. After running jl.config, it shows: cmd = 'println(Base.JLOptions().debug_level > 1)'; [~, dbg] = system(sprintf('"%s" -e "%s"', exe, cmd)); dbg = jl.chomp(dbg); jl.set('is_debug', dbg);

The path is pointing toward julia v5.0. I still keep v0.4.6 though.

Thank you! Huy

laughingrice commented 7 years ago

Version 0.5.0 (2016-09-19 18:14 UTC) Official http://julialang.org/ release x86_64-w64-mingw32

I tried running julia-debug as well, no such field. Also checked on my mac.

Might you be running the nightly build rather than the release version?

twadleigh commented 7 years ago

That may be the issue. Both julia and julia-debug have that field (with different values) in their respective JLOptions. The purpose of that test was (obviously) to distinguish the two versions. Looks like I may need a different test for debug for 0.5.

laughingrice commented 7 years ago

As a partial workaround, I've ended up with this. If the field exists it is checked whether debug is enabled, otherwise it sets debug to false

  cmd = 'print(:debug_level in fieldnames(Base.JLOptions()))';
  [~, dbg] = system(sprintf('"%s" -e "%s"', exe, cmd));
  jl.chomp(dbg);
  if strcmp(dbg, 'true')
      cmd = 'println(Base.JLOptions().debug_level > 1)';
      [~, dbg] = system(sprintf('"%s" -e "%s"', exe, cmd));
      jl.chomp(dbg);
  end
  jl.set('is_debug', dbg);

I've seen that you have fixed the later test on dbg so that it does not always evaluate to true.

At least on my system, I also need to remove libopenlibm.dll.a from the library list as julia 0.5.0 does not seem to provide it and it does not seem to be needed.

Also on the compile command, it requires another set of quote marks on the second to last %s in order to correctly handle paths with spaces, i.e replace

   mex_ptrn = 'mex -largeArrayDims -outdir "%s" %s %s %s %s';

with

   mex_ptrn = 'mex -largeArrayDims -outdir "%s" %s %s "%s" %s';

There are a couple other suggested changes that I'll put elsewhere not to mix things.

Finally as a side comment, on a mac this crashes matlab immediately without a warning (the call to jl_init_with_image). It looks like there is a conflict with the versions of libgmp and libcurl. I don't know if it won't bite me on my behind at a later point, but the solution for now was to go into /Applications/MATLAB_R2016b.app/bin/maci64 and replace the matlab versions with the julia ones, i.e

   rm libgmp.dylib 
   ln -s /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/libgmp.dylib 
   ln -s /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/libcurl.dylib

I don't know if matlab won't complain at some later point as I don't know which part of matlab uses them

Hope that some of this helps

twadleigh commented 7 years ago

ccall(:jl_is_debugbuild, Cint, ()) != 0 is the right backwards compatible test for the debug version.

libopenlibm.dll is not required for a successful link of mexjulia, although it is required, in general, for embedding on windows. MATLAB happens to provide the missing symbols.

twadleigh commented 7 years ago

I've made some updates to deal with many of these issues. Unfortunately, I'm still not able to get mexjulia running on Ubuntu.

I'm closing this. Please open new issues as you find them.