DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
222 stars 49 forks source link

Issue launching DIPimage from Matlab macOS Sonoma #169

Open J-Ratcliff opened 1 week ago

J-Ratcliff commented 1 week ago

Component Select one or more of: DIPviewer / DIPimage / CMake build scripts Git commit ID 7a81be4

Describe the bug I followed the instructions for building DIPlib on macOS but when I tried to run dipimage in Matlab the GUI didn't load properly (no version number or options besides File I/O and Help) and I got:

image

I then realised my Matlab path was '/Users/uname/src/diplib' instead of '/usr/local/share/DIPimage' or '/home/uname/share/DIPimage'. I looked in both locations and the share folder isn't in either of them so I believe this may be a cmake issue?

After cmake .. I get the following in the configuration report:

--------------------------------------
   DIPlib CONFIGURATION REPORT

 * PROJECT_VERSION: 3.5.1
 * DIP_COPYRIGHT_YEAR: 2024
 * C++ compiler: AppleClang 15.0.0.15000309
 * C++ compiler flags: -march=native -Wall -Wconversion -Wsign-conversion -pedantic -Wno-c++17-extensions -Wno-unused-command-line-argument 
 * Build type: Release
 * Building shared library
 * Library installed to: /usr/local/lib
 * Binaries installed to: /usr/local/bin
 * Header files installed to: /usr/local/include
 * dox++ program not configured, no documentation can be generated
 * Using OpenMP for multithreading
 * Stack trace recording enabled
 * Asserts disabled
 * Unicode support enabled
 * Using 128-bit PRNG
 * ICS file IO enabled, with zlib
 * TIFF file IO enabled, with zlib, with JPEG
 * JPEG file IO enabled
 * PNG file IO enabled
 * Using PocketFFT
 * Not using FreeType
 * Unit test code included
 * DIPviewer module added to 'all' with window managers: GLFW
 * DIPjavaio module added to 'all' target with interfaces: Bio-Formats
 * DIPjavaio compiled using Java version 17.0.10 and targeting 1.8
 * PyDIP module added to 'all' target
 * PyDIP compiled for Python version 3.11.5
 * PyDIP does not include libraries in binary wheel
 * DIPimage toolbox added to 'all' target
 * DIPimage toolbox compiled for MATLAB R2022b
 * DIPviewer Java bindings added to 'all' target, compiled using Java version 17.0.10 and targeting 1.8
 * DIPimage toolbox installed to: /usr/local/share/DIPimage
 * DIPimage User Manual cannot be created (dox++ program not configured)

Next, type 'make; make check; make install'

--------------------------------------

-- Configuring done (39.2s)
-- Generating done (0.6s)
-- Build files have been written to: /Users/u2254386/src/diplib/target

make -j check passes everything with two warnings:

 [  9%] Building C object libjpeg/CMakeFiles/jpeg.dir/jcmarker.c.o 
warning: [options] bootstrap class path not set in conjunction with -source 8
[ 88%] Linking CXX shared library libDIP.dylib
ld: warning: ignoring duplicate libraries: '../libjpeg/libjpeg.a'

make -j install produces the following:

[  4%] Built target zlibstatic
[ 16%] Built target jpeg
[ 17%] Generating Contents.m
[ 21%] Built target libics
[ 22%] Building Java objects for ViewerJava.jar
[ 23%] Built target DIPjavaio_java
[ 23%] Built target spng_static
[ 32%] Built target tiff
warning: [options] bootstrap class path not set in conjunction with -source 8
/Users/u2254386/src/diplib/viewer/java/Viewer.java:110: error: cannot find symbol
        proxy_ = Native.load("DIPviewer", Proxy.class);
                       ^
  symbol:   method load(String,Class<Proxy>)
  location: class Native
1 error
1 warning
make[2]: *** [dipimage/CMakeFiles/ViewerJava.dir/java_compiled_ViewerJava] Error 1
make[1]: *** [dipimage/CMakeFiles/ViewerJava.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 74%] Built target DIP
Creating Contents.m in /Users/u2254386/src/diplib/target/dipimage
[ 74%] Built target contents
make: *** [all] Error 2

I'm not sure what of the above (if any) is the exact source of my issue is and I've tried a few things like adding the -DCMAKE_INSTALL_PREFIX=$HOME/dip flag to cmake and changing to the latest JNA JAR file as in #151 but nothing I've tried so far has worked. Any help or suggestions would be greatly appreciated.

System information:

crisluengo commented 1 week ago

The reason DIPimage doesn’t work is because the installation never completed. It stopped with an error trying to build the Java interface to DIPviewer.

You already tried upgrading the JNI version that comes with MATLAB. What Java JDK did you install? MATLAB R2022b only had an Intel build, I believe? Do you have an Intel-based Mac? Or are you using an Intel build of MATLAB on an Apple Silicon Mac? In the latter case, you need to make sure you build DIPlib for the Intel architecture!

You have two options to continue from here:

  1. The easy way out is to not build DIPviewer. Add -DIP_BUILD_DIPVIEWER=Off to your CMake command (and then run make install again; this will not rebuild DIPlib, just continue with the installation where you left off). DIPimage doesn’t really need DIPviewer, there’s an interactive display utility written in MATLAB that works really well (and is the default). DIPviewer improves on it in some ways, but is really intended to provide a display utility for use in C++ and Python.

  2. Try fixing this issue, which likely involves upgrading your JDK, or otherwise figuring out what the issue might be.

J-Ratcliff commented 1 week ago

Thanks for the quick response. I'll try not building DIPviewer and see how that goes. My Mac is Apple Silicon based and I can also use MATLAB R2024a as I did not realise R2022b was an Intel only build. May be worth adding to the building page that latest versions of MATLAB means R2023b and up? I didn't realise that my R2022b version meant I should have been building for x86_64 architecture. I'll update this thread with my progress.

J-Ratcliff commented 1 week ago

After running cmake .. -DDIP_BUILD_DIPVIEWER=Off -DMatlab_ROOT_DIR=/Applications/MATLAB_R2024a.app I got the following at the end of the configuration report:

* DIPimage toolbox added to 'all' target
CMake Warning at tools/FindMatlab.cmake:392 (message):
  [MATLAB] The version 24.1 is not registered
Call Stack (most recent call first):
  CMakeLists.txt:363 (matlab_get_release_name_from_version)

 * DIPimage toolbox compiled for MATLAB 

This seems to be a similar issue to issue #115, should I try deleting the CMakeCache.txt file from the diplib/target directory and running cmake again?

crisluengo commented 1 week ago

The CMake script to deal with MATLAB has a list of MATLAB version numbers to translate the release (R2022a) to a version number (9.12). R2024a was not yet listed, hence your error. If you git pull you'll get the updated script and you should be able to finish building DIPimage. Just do a cmake . to update the configuration.

I've added some clarity around Apple Silicon and Intel versions of MATLAB, including a way to find out which one you have: https://github.com/DIPlib/diplib/blob/master/doc/src/Build/macOS.md (not yet on the home page). I'd love to hear how else to improve the build instructions.

J-Ratcliff commented 1 week ago

Hi again, after git pull and cmake . the DIPimage toolbox compiled for R2024a and make -j check didn't throw any errors but when I ran make -j install right at the end I got:

image

I was worried about this and assume it is due to some restrictions on my machine as it semi managed by my organisation. Thanks to the documentation advice I then tried cmake . -DCMAKE_INSTALL_PREFIX=$HOME/dip and both make steps completed which was promising. Unfortunately now after launching MATLAB and adding dip/share/DIPimage to the path when I try and run the dipimage command MATLAB immediately crashes. I have pasted the crash report below but I am not really sure what I need to be looking out for. I can add the cmake . -DCMAKE_INSTALL_PREFIX=$HOME/dip summary if needed.

The updated documentation looks good - even though I made a few mistakes I have to say the documentation made trying compiling and cmake for the first time a lot less intimidating!

MATLAB Log File: /Users/u2254386/matlab_crash_dump.85337-1

------------------------------------------------
MATLAB Log File
------------------------------------------------ 

--------------------------------------------------------------------------------
                 abort() detected at 2024-09-19 13:40:56 +0100
--------------------------------------------------------------------------------

Configuration:
  Crash Decoding           : Disabled - No sandbox or build area path
  Crash Mode               : continue (default)
  Default Encoding         : UTF-8
  Deployed                 : false
  Graphics Driver          : Uninitialized hardware 
  Java Version             : Java 11.0.24+8-LTS with Amazon.com Inc. OpenJDK 64-Bit Server VM mixed mode
  MATLAB Architecture      : maca64
  MATLAB Entitlement ID    : 1447274
  MATLAB Root              : /Applications/MATLAB_R2024a.app
  MATLAB Version           : 24.1.0.2689473 (R2024a) Update 6
  OpenGL                   : hardware
  Operating System         : Mac OS Version 14.6.1 (Build 23G93)
  Process ID               : 85337
  Processor ID             : ABI64 ARM ARM64E FIRESTORM_ICESTORM
  Session Key              : 745789e5-01c4-4b61-9a46-13757d52b25b
  Window System            : Quartz

Fault Count: 1

Abnormal termination:
abort()

Current Thread: 'MCR 0 interpreter thread' id 0x16f363000

Register State (from fault):
   X0 = 0000000000000000   X1 = 0000000000000000
   X2 = 0000000000000000   X3 = 0000000000000000
   X4 = 0000000040001000   X5 = 0000000000000020
   X6 = 0000000000000000   X7 = 00000000000002c0
   X8 = 9cb90ac8695a24b7   X9 = 9cb90ac9066c14b7
  X10 = 0000000000179f41  X11 = 000000000012edc0
  X12 = 00000003d7403fc0  X13 = 0000000000000026
  X14 = 00000003d7400000  X15 = 0000000000000000
  X16 = 0000000000000148  X17 = 00000001f2aee4e8
  X18 = 0000000000000000  X19 = 0000000000000006
  X20 = 000000016f363000  X21 = 000000000000d603
  X22 = 000000016f3630e0  X23 = 0000000331050000
  X24 = 00000000000001b6  X25 = 00000003d7409c70
  X26 = 00000003d7441a20  X27 = 0000000000000000
  X28 = 00000003d7441a35

   FP = 000000016f35b4a0   LR = 000000018059dc20
   SP = 000000016f35b480   PC = 00000001805655f0

 CPSR = 40001000

Stack Trace (from fault):
[  0] 0x00000001035aaca0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwfl.dylib+00011424 _ZN10foundation4core4diag15stacktrace_base7captureERKNS1_14thread_contextEm+00000064
[  1] 0x00000001035adb68 /Applications/MATLAB_R2024a.app/bin/maca64/libmwfl.dylib+00023400 _ZN10foundation4core4test17terminate_handledERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE+00002144
[  2] 0x00000001035ad028 /Applications/MATLAB_R2024a.app/bin/maca64/libmwfl.dylib+00020520 _ZN10foundation4core4diag13terminate_logEPKcPK17__darwin_ucontext+00000140
[  3] 0x000000010a421de0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00482784 _Z19mnPrintErrorMessageRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+00011892
[  4] 0x000000010a41fc80 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00474240 _Z19mnPrintErrorMessageRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+00003348
[  5] 0x000000010a423eac /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00491180 _Z19mnPrintErrorMessageRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+00020288
[  6] 0x000000010a41eb04 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00469764 _Z22mnInstallCrashHandlersv+00000392
[  7] 0x00000001805ce584           /usr/lib/system/libsystem_platform.dylib+00017796 _sigtramp+00000056
[  8] 0x000000018059dc20            /usr/lib/system/libsystem_pthread.dylib+00027680 pthread_kill+00000288
[  9] 0x00000001804aaa30                  /usr/lib/system/libsystem_c.dylib+00485936 abort+00000180
[ 10] 0x0000000330feb400                        /usr/local/lib/libomp.dylib+00095232 __kmp_unregister_library+00000000
[ 11] 0x0000000330fe9eb0                        /usr/local/lib/libomp.dylib+00089776 __kmp_vprintf+00000000
[ 12] 0x0000000330ff1d8c                        /usr/local/lib/libomp.dylib+00122252 _Z30__kmp_register_library_startupv+00000876
[ 13] 0x0000000330fea3d8                        /usr/local/lib/libomp.dylib+00091096 _ZL26__kmp_do_serial_initializev+00000032
[ 14] 0x0000000330ff1f6c                        /usr/local/lib/libomp.dylib+00122732 _ZL26__kmp_do_middle_initializev+00000036
[ 15] 0x0000000330ff1f30                        /usr/local/lib/libomp.dylib+00122672 __kmp_middle_initialize+00000068
[ 16] 0x0000000331039f7c                        /usr/local/lib/libomp.dylib+00417660 omp_get_max_threads+00000024
[ 17] 0x000000018022e608                                      /usr/lib/dyld+00136712 ___ZZNK5dyld46Loader25findAndRunAllInitializersERNS_12RuntimeStateEENK3$_0clEv_block_invoke+00000168
[ 18] 0x000000018026cd6c                                      /usr/lib/dyld+00392556 ___ZNK5dyld313MachOAnalyzer18forEachInitializerER11DiagnosticsRKNS0_15VMAddrConverterEU13block_pointerFvjEPKv_block_invoke.209+00000340
[ 19] 0x0000000180260400                                      /usr/lib/dyld+00340992 ___ZNK5dyld39MachOFile14forEachSectionEU13block_pointerFvRKNS0_11SectionInfoEbRbE_block_invoke+00000496
[ 20] 0x000000018020f2fc                                      /usr/lib/dyld+00008956 _ZNK5dyld39MachOFile18forEachLoadCommandER11DiagnosticsU13block_pointerFvPK12load_commandRbE+00000300
[ 21] 0x000000018025f394                                      /usr/lib/dyld+00336788 _ZNK5dyld39MachOFile14forEachSectionEU13block_pointerFvRKNS0_11SectionInfoEbRbE+00000192
[ 22] 0x000000018026c880                                      /usr/lib/dyld+00391296 _ZNK5dyld313MachOAnalyzer18forEachInitializerER11DiagnosticsRKNS0_15VMAddrConverterEU13block_pointerFvjEPKv+00000516
[ 23] 0x000000018022a53c                                      /usr/lib/dyld+00120124 _ZNK5dyld46Loader25findAndRunAllInitializersERNS_12RuntimeStateE+00000564
[ 24] 0x0000000180230bc0                                      /usr/lib/dyld+00146368 _ZNK5dyld416JustInTimeLoader15runInitializersERNS_12RuntimeStateE+00000036
[ 25] 0x000000018022a984                                      /usr/lib/dyld+00121220 _ZNK5dyld46Loader23runInitializersBottomUpERNS_12RuntimeStateERN5dyld35ArrayIPKS0_EE+00000220
[ 26] 0x000000018022a928                                      /usr/lib/dyld+00121128 _ZNK5dyld46Loader23runInitializersBottomUpERNS_12RuntimeStateERN5dyld35ArrayIPKS0_EE+00000128
[ 27] 0x000000018022e698                                      /usr/lib/dyld+00136856 _ZZNK5dyld46Loader38runInitializersBottomUpPlusUpwardLinksERNS_12RuntimeStateEENK3$_1clEv+00000116
[ 28] 0x000000018022ab78                                      /usr/lib/dyld+00121720 _ZNK5dyld46Loader38runInitializersBottomUpPlusUpwardLinksERNS_12RuntimeStateE+00000420
[ 29] 0x0000000180246d30                                      /usr/lib/dyld+00236848 _ZN5dyld44APIs11dlopen_fromEPKciPv+00001876
[ 30] 0x0000000103c9e3fc /Applications/MATLAB_R2024a.app/bin/maca64/libut.dylib+00025596 _Z19utLoadLibraryHelperRKNSt3__112basic_stringIDsNS_11char_traitsIDsEENS_9allocatorIDsEEEEPii+00000376
[ 31] 0x0000000103c9f074 /Applications/MATLAB_R2024a.app/bin/maca64/libut.dylib+00028788 _Z38utLoadLibraryWithLocalSymbolVisibilityRKNSt3__112basic_stringIDsNS_11char_traitsIDsEENS_9allocatorIDsEEEEPi+00000100
[ 32] 0x000000010ba01a14 /Applications/MATLAB_R2024a.app/bin/maca64/libmex.dylib+00432660 _ZN13MexFileReader7loadMexEPKDsPKcPi+00001132
[ 33] 0x000000010b9ecb48 /Applications/MATLAB_R2024a.app/bin/maca64/libmex.dylib+00346952 _ZN7Mlm_mex9load_fileEv+00000184
[ 34] 0x000000010a6a724c /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_dispatcher.dylib+00717388 _ZN8Mlm_file7load_mfEv+00000168
[ 35] 0x000000010a60e5d0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_dispatcher.dylib+00091600 _ZN18Mlm_MATLAB_fn_impl8try_loadEv+00000056
[ 36] 0x000000010a60e8f0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_dispatcher.dylib+00092400 _ZN18Mlm_MATLAB_fn_impl4loadEv+00000060
[ 37] 0x000000010a6a44d8 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_dispatcher.dylib+00705752 _ZNK8Mfh_file29ensure_loading_of_load_moduleEv+00000040
[ 38] 0x000000010a6a4cac /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_dispatcher.dylib+00707756 _ZN8Mfh_file8dispatchEiPNSt3__110unique_ptrI11mxArray_tagN6matrix6detail17mxDestroy_deleterEEEiPPS2_+00000084
[ 39] 0x000000010cda0ec0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+00511680 _ZN9MathWorks3lxe13LxeDispatcher12apply_handleEP13Mfh_MATLAB_fnPKS2_mPNS0_6xvalueEmPKS6_RKNS0_12LxeTypesBaseENS0_9ApplyTypeE+00000640
[ 40] 0x00000001115af47c /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+04125820 _ZN9MathWorks3lxe12apply_handleEPvNS_2ts4TypeEPKvS1_S1_+00000352
[ 41] 0x00000001114f680c /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+03368972 _ZN9MathWorks3lxe38cpp_primitive_template_fn_with_contextIXadL_ZNS0_12apply_handleEPvNS_2ts4TypeEPKvS2_S2_EEEEbS2_S4_S6_S2_S2_+00000020
[ 42] 0x00000001112b8570 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01017200 _ZN9MathWorks3lxe13IrInterpreter17ApplyCppPrimitiveEPN2ir4termES4_RKNS_2ts4TypeES8_+00000708
[ 43] 0x00000001112b7230 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01012272 _ZN9MathWorks3lxe13IrInterpreter31process_application_of_constantEPN2ir4termE+00000988
[ 44] 0x00000001112b5740 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01005376 _ZN9MathWorks3lxe13IrInterpreter13applyConstantEPN2ir4termE+00000136
[ 45] 0x00000001112ca778 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01091448 _ZN9MathWorks3lxe12IRTreeWalker11getNextIRPCENS0_9irpc_typeE+00000848
[ 46] 0x00000001112b5480 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01004672 _ZN9MathWorks3lxe13IrInterpreter9tree_walkERKNS0_9irpc_typeES4_+00000216
[ 47] 0x00000001112b5368 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+01004392 _ZN9MathWorks3lxe13IrInterpreter9InterpretEv+00000108
[ 48] 0x00000001113d7b48 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+02194248 _ZN9MathWorks3lxe15ExecutionDriver9ThreadRunEv+00003812
[ 49] 0x00000001113dcce0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwm_lxe.dylib+02215136 _ZN9MathWorks3lxe12IrEngineImpl5ApplyERKN2ir4termEPvS6_+00000328
[ 50] 0x000000010cf03370 /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+01962864 _ZN9MathWorks3lxe17IrEngineDecorator5ApplyERKN2ir4termEPvS6_+00000100
[ 51] 0x000000010cdfaab4 /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+00879284 _ZN9MathWorks3lxe9Evaluator15ApplyStatementsERKNSt3__112basic_stringIDsNS2_11char_traitsIDsEENS2_9allocatorIDsEEEERKN2ir4termERNS0_18IEvaluationContextE+00000496
[ 52] 0x000000010ce001ac /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+00901548 _ZN9MathWorks3lxe9Evaluator17EvalStatementImplERKNSt3__112basic_stringIDsNS2_11char_traitsIDsEENS2_9allocatorIDsEEEERNS0_18IEvaluationContextE+00000440
[ 53] 0x000000010cea9140 /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+01593664 _ZN9MathWorks3lxe9LxeBridge7EvalCmdERKNSt3__112basic_stringIDsNS2_11char_traitsIDsEENS2_9allocatorIDsEEEEbNS0_10EvalSourceE+00000368
[ 54] 0x000000010cea8f78 /Applications/MATLAB_R2024a.app/bin/maca64/libmwlxemainservices.dylib+01593208 _ZN9MathWorks3lxe9LxeBridge22EvalCmdWithLocalReturnERKNSt3__112basic_stringIDsNS2_11char_traitsIDsEENS2_9allocatorIDsEEEEPibNS0_10EvalSourceE+00000068
[ 55] 0x000000010a32d250 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00561744 _ZN3iqm14UserEvalPlugin7executeEP15inWorkSpace_tag+00000580
[ 56] 0x0000000146e77000 /Applications/MATLAB_R2024a.app/bin/maca64/libnativejmi.dylib+00110592 _ZN9nativejmi17JmiUserEvalPlugin7executeEP15inWorkSpace_tag+00000032
[ 57] 0x000000010a301664 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00382564 _ZN3iqm17DefaultPacketInfo7executeEP15inWorkSpace_tagRKN7mwboost10shared_ptrINS_22IntermediatePacketInfoEEEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueE+00001268
[ 58] 0x000000010a314c80 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00461952 _ZN3iqm10ioreadline14EvalPacketInfo7executeEP15inWorkSpace_tagRKN7mwboost10shared_ptrINS_22IntermediatePacketInfoEEEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueE+00000144
[ 59] 0x000000010a2b2550 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00058704 _ZN3iqm10DefaultIqm7dequeueERKN7mwboost8optionalIKP15inWorkSpace_tagEEN14cmddistributor11IqmStreamIDERKNS1_9function2IN6mlutil14cmddistributor17inExecutionStatusERKNSt3__112basic_stringIDsNSF_11char_traitsIDsEENSF_9allocatorIDsEEEES5_EE+00004328
[ 60] 0x000000010b85b9d8 /Applications/MATLAB_R2024a.app/bin/maca64/libmwbridge.dylib+00063960 _Z10ioReadLinebP7__sFILERKN7mwboost8optionalIKP15inWorkSpace_tagEEbRbRKNS1_9function2IN6mlutil14cmddistributor17inExecutionStatusERKNSt3__112basic_stringIDsNSE_11char_traitsIDsEENSE_9allocatorIDsEEEES5_EE+00000212
[ 61] 0x000000010b87c0f0 /Applications/MATLAB_R2024a.app/bin/maca64/libmwbridge.dylib+00196848 _Z22mnGetCommandLineBufferbRbN7mwboost8optionalIKP15inWorkSpace_tagEEbRKNS0_9function2IN6mlutil14cmddistributor17inExecutionStatusERKNSt3__112basic_stringIDsNSA_11char_traitsIDsEENSA_9allocatorIDsEEEES4_EE+00000288
[ 62] 0x000000010b87c698 /Applications/MATLAB_R2024a.app/bin/maca64/libmwbridge.dylib+00198296 _Z8mnParserv+00000436
[ 63] 0x000000010a3ec578 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00263544 _ZN3mcr7runtime13initializeIqmERKN6mlutil10contextmgr5McrIDE+00005320
[ 64] 0x000000010a3ced50 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00142672 _ZN14cmddistributor15PackagedTaskIIP13getTypeStringIvEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEv+00000928
[ 65] 0x000000010a3cec0c /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00142348 _ZN14cmddistributor15PackagedTaskIIP13getTypeStringIvEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEv+00000604
[ 66] 0x000000010a328a48 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00543304 _ZN3iqm18PackagedTaskPlugin7executeEP15inWorkSpace_tag+00000088
[ 67] 0x000000010a301664 /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00382564 _ZN3iqm17DefaultPacketInfo7executeEP15inWorkSpace_tagRKN7mwboost10shared_ptrINS_22IntermediatePacketInfoEEEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueE+00001268
[ 68] 0x000000010a2c138c /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00119692 _ZN3iqm10DefaultIqm13dequeueHelperEN7mwboost8optionalImEERKNSt3__112basic_stringIDsNS4_11char_traitsIDsEENS4_9allocatorIDsEEEEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueERKNS4_8functionIFbRKNS4_5tupleIJSG_NS1_10shared_ptrINS_22IntermediatePacketInfoEEESA_SA_NS4_10shared_ptrIN14cmddistributor16CoalesceableDataEEEEEEEEE+00001356
[ 69] 0x000000010a2b455c /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00066908 _ZN3iqm10DefaultIqm15dequeueInternalEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueEN7mwboost8optionalImEE+00000860
[ 70] 0x000000010a2c17bc /Applications/MATLAB_R2024a.app/bin/maca64/libmwiqm.dylib+00120764 _ZN3iqm10DefaultIqm7dequeueEN6mlutil14cmddistributor13WhenToDequeue13WhenToDequeueEN7mwboost8optionalImEE+00000124
[ 71] 0x000000010a3d98cc /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00186572 _ZN3mcr7runtime22InterpreterThreadMulti14process_eventsEv+00000228
[ 72] 0x000000010a3da054 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00188500 _ZN3mcr7runtime22InterpreterThreadMulti10threadMainENSt3__18functionIFvvEEENS2_7promiseIvEE+00000372
[ 73] 0x000000010a3db908 /Applications/MATLAB_R2024a.app/bin/maca64/libmwmcr.dylib+00194824 _ZN3mcr7runtime22InterpreterThreadMulti10threadMainENSt3__18functionIFvvEEENS2_7promiseIvEE+00006696
[ 74] 0x0000000103482868 /Applications/MATLAB_R2024a.app/bin/maca64/libmwboost_thread.dylib+00010344 _ZN7mwboost6thread21start_thread_noexceptEv+00000444
[ 75] 0x000000018059df94            /usr/lib/system/libsystem_pthread.dylib+00028564 _pthread_start+00000136
[ 76] 0x0000000180598d34            /usr/lib/system/libsystem_pthread.dylib+00007476 thread_start+00000008

This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
crisluengo commented 1 week ago

Glad there's progression!

In your stack trace, I see

/usr/local/lib/libomp.dylib+00417660 omp_get_max_threads+00000024

On my Mac, this library is at /opt/homebrew/opt/libomp/lib/libomp.dylib. /usr/local/ is where the x86_64 version of Homebrew installs stuff. The arm64 version installs at /opt/homebrew/.

Did you do brew install libomp in a terminal in x86_64 emulation mode? Though I would expect the linker to fail if it tried to link to a non-arm64 library, so that cannot be it...


The other thing I notice in the stack trace is that there's nothing under the $HOME/dip/ directory referenced. So this error is happening entirely within MATLAB compiled code.

Are you able to run other MATLAB code that does not relate to DIPimage?

My MATLAB does come with its own libomp.dylib:

/Applications/MATLAB_R2023b.app/bin/maca64/libomp.dylib

It is entirely possible that the libomp.dylib library you have under /usr/local/ is shadowing the one that comes with MATLAB, and that these two versions are not compatible.

I would start by deleting (or moving, or renaming) /usr/local/lib/libomp.dylib, then trying to run MATLAB again.

J-Ratcliff commented 5 days ago

Renaming the libomp.dylib under usr worked to stop MATLAB crashing on running dipimage. Now I get:

Warning: Call to DIPMENUS failed:

Invalid MEX-file '/Users/uname/dip/share/DIPimage/measure.mexmaca64': dlopen(/Users/uname/dip/share/DIPimage/measure.mexmaca64, 0x0006): Library not loaded: /usr/local/lib/libomp.dylib
  Referenced from: <AAACC09E-B47F-35B7-851E-1361C2F2BDA5> /Users/uname/dip/lib/libDIP.dylib
  Reason: tried: '/usr/local/lib/libomp.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file)

Invalid MEX-file '/Users/uname/dip/share/DIPimage/private/numberofthreads.mexmaca64':
dlopen(/Users/uname/dip/share/DIPimage/private/numberofthreads.mexmaca64, 0x0006): Library
not loaded: /usr/local/lib/libomp.dylib
  Referenced from: <AAACC09E-B47F-35B7-851E-1361C2F2BDA5> /Users/uname/dip/lib/libDIP.dylib
  Reason: tried: '/usr/local/lib/libomp.dylib' (no such file),
  '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/libomp.dylib' (no such file),
  '/usr/local/lib/libomp.dylib' (no such file)

Error in dippreferences (line 76)
      'NumberOfThreads',         struct('type','integer','value',numberofthreads),...

Error in dipgetpref (line 51)
      pref = dippreferences('get',name);

Error in dipinit (line 38)
dipinit_ws = [dipgetpref('DefaultFigureWidth'),dipgetpref('DefaultFigureHeight')];

Error in dipimage/do_start (line 111)
   evalin('base','dipinit');

Error in dipimage (line 48)
   do_start;

So it seems MATLAB is not trying to find another libomp.dylib after failing to find the one at usr/local/lib/libomp.dylib. I have checked and libomp.dylib is located in both /opt/homebrew/opt/libomp/lib/libomp.dylib and /Applications/MATLAB_R2024a.app/bin/maca64/libomp.dylib.

I assume I now need a way of telling MATLAB to use one of these instead?

crisluengo commented 5 days ago

It looks like the DIPlib library you built was linking against /usr/local/lib/libomp.dylib (the path would be explicitly included here). I don’t really understand why the arm64 linker tried linking against an x86_64 library, but it did.

I’m not sure how to fix this, other than simply trying again now that you don’t have that library any more. You have /opt/homebrew/opt/libomp/lib/libomp.dylib, and CMake should be able to find it. Does running CMake again update the OpenMP library that is linked against?

Delete libdip.dylib in your build directory and run make again (or do make clean && make). Does this complain about a missing libomp.dylib?

If it fails that way, you’ll have to delete your CMakeCache file, and do the CMake configuration step again from scratch. All the options you’ve passed before you’ll have to pass again. But hopefully now the OpenMP library is the right one!

J-Ratcliff commented 3 days ago

Yep it complained when running make clean && make, I got:

 77%] Building CXX object src/CMakeFiles/DIP.dir/transform/swt.cpp.o
make[2]: *** No rule to make target `/usr/local/lib/libomp.dylib', needed by `src/libDIP.dylib'.  Stop.
make[1]: *** [src/CMakeFiles/DIP.dir/all] Error 2
make: *** [all] Error 2

Deleting the CMakeCache file and running make with all the configuration steps (cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/dip -DDIP_BUILD_DIPVIEWER=OFF -DMatlab_ROOT_DIR=/Applications/MATLAB_R2024a.app) initially gave :

Detecting CXX compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 

, which worried me a bit, but after running the make steps again I was able to run DIPimage from MATLAB and it seemed to launch properly with the full menu and default display windows, so I think I'm good to go now.

Thanks again for all your help!

crisluengo commented 3 days ago

Glad you got it working!

You're now not using any multithreading, which might have a noticeable impact, depending on what you intend to do with the toolbox.

Try adding -DCMAKE_CXX_FLAGS="-I/opt/homebrew/opt/libomp/include -L/opt/homebrew/opt/libomp/lib" to your CMake command, then look for "Using OpenMP for multithreading" in the configuration report. make install should then rebuild the library with multithreading.

J-Ratcliff commented 3 days ago

I tried adding the flags using cmake . but I don't think it worked, or at least I can't see it 'Using OpenMP for multithreading' in the report:

-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 
~~~Configuring Zlib~~~
~~~
~~~Configuring libics~~~
~~~Configuring LibTIFF~~~
-- LibTIFF uses win32 IO: FALSE
-- LibTIFF has JPEG 8/12 bit dual mode: FALSE
~~~
-- GLFW found: /opt/homebrew/lib/libglfw.dylib -- /opt/homebrew/include
-- pybind11 v2.12.0 

--------------------------------------
   DIPlib CONFIGURATION REPORT

 * PROJECT_VERSION: 3.5.1
 * DIP_COPYRIGHT_YEAR: 2024
 * C++ compiler: AppleClang 15.0.0.15000309
 * C++ compiler flags: -I/opt/homebrew/opt/libomp/include -L/opt/homebrew/opt/libomp/lib -Wall -Wconversion -Wsign-conversion -pedantic -Wno-c++17-extensions -Wno-unused-command-line-argument -O3 -DNDEBUG
 * Build type: Release
 * Building shared library
 * Library installed to: /Users/u2254386/dip/lib
 * Binaries installed to: /Users/u2254386/dip/bin
 * Header files installed to: /Users/u2254386/dip/include
 * dox++ program not configured, no documentation can be generated
 * Multithreading disabled
 * Stack trace recording enabled
 * Asserts disabled
 * Unicode support enabled
 * Using 128-bit PRNG
 * ICS file IO enabled, with zlib
 * TIFF file IO enabled, with zlib, with JPEG
 * JPEG file IO enabled
 * PNG file IO enabled
 * Using PocketFFT
 * Not using FreeType
 * Unit test code included
 * DIPviewer module not configured
 * DIPjavaio module added to 'all' target with interfaces: Bio-Formats
 * DIPjavaio compiled using Java version 17.0.10 and targeting 1.8
 * PyDIP module added to 'all' target
 * PyDIP compiled for Python version 3.11.5
 * PyDIP does not include libraries in binary wheel
 * DIPimage toolbox added to 'all' target
 * DIPimage toolbox compiled for MATLAB R2024a
 * DIPviewer Java bindings not configured
 * DIPimage toolbox installed to: /Users/u2254386/dip/share/DIPimage
 * DIPimage User Manual cannot be created (dox++ program not configured)

What else could I try? I think multithreading could be useful for me.

crisluengo commented 2 days ago

Sorry, I thought I was doing it right, but I wasn't. I just tried this myself with a configuration similar to yours, and I needed to add the following to my CMake command: -DOpenMP_CXX_INCLUDE_DIR=/opt/homebrew/opt/libomp/include -DCMAKE_CXX_FLAGS=-L/opt/homebrew/opt/libomp/lib

I'm not really sure why this particular combination works, but leaving either out results in CMake not finding OpenMP. The OpenMP_CXX_INCLUDE_DIR flag is described in the CMake documentation, way at the bottom of the page: https://cmake.org/cmake/help/latest/module/FindOpenMP.html.