dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

MAUI .NET 6/7 Library not loaded: @rpath/liblua54.framework/Versions/A/liblua54 #20026

Closed Jurashikku closed 8 months ago

Jurashikku commented 8 months ago

Description

After create clear maui app .net 7 add Lua lib to project ( NLua 1.6.3 ) Run on windows success, but when try run on MacOs run project crash with error Library not loaded: @rpath/liblua54.framework/Versions/A/liblua54

When go to /ClearMauiLuaApp.app/Contents/Frameworks/liblua54.framework/liblua54 - exist but the request path /Versions/A/ - not created so dll not found.

Steps to Reproduce

MacOs (13.6.3) VisualStudio for Mac (17.6.8 (build 400))

  1. Create Maui App .net 7
  2. Add NLua 1.6.3 from NuGet
  3. In MainPage.xml.cs add var lua = new Lua();
  4. run debug app.

Link to public reproduction project repository

No response

Version with bug

7.0.101

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

MacOs 13.6.3

Did you find any workaround?

Not yet.

Relevant log output

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               ClearMauiLuaApp [22810]
Path:                  /Users/USER/*/ClearMauiLuaApp.app/Contents/MacOS/ClearMauiLuaApp
Identifier:            com.companyname.clearmauiluaapp
Version:               1.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-01-20 15:18:04.5168 +0300
OS Version:            macOS 13.6.3 (22G436)
Report Version:        12
Bridge OS Version:     3.0 (14Y910)
Anonymous UUID:        A3A6B850-4D11-D8B5-F769-235CF69CF693

Sleep/Wake UUID:       B7D41381-35B8-48B9-A471-96D8F2E5E9F1

Time Awake Since Boot: 67000 seconds
Time Since Wake:       7034 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: @rpath/liblua54.framework/Versions/A/liblua54
Referenced from: <FE058360-8185-335B-BB83-01B712F7F81B> /Users/USER/*/ClearMauiLuaApp.app/Contents/MacOS/ClearMauiLuaApp
Reason: tried: '/Users/yurasultanov/Projects/ClearMauiLuaApp/ClearMauiLuaApp/bin/Debug/net7.0-maccatalyst/maccatalyst-x64/ClearMauiLuaApp.app/Contents/Frameworks/liblua54.framework/Versions/A/liblua54' (no such file), '/Users/yurasultanov/Projects/ClearMauiLuaApp/ClearMauiLuaApp/bin/Debug/net7.0-maccatalyst/maccatalyst-x64/ClearMauiLuaApp.app/Contents/Frameworks/liblua54.framework/Versions/A/liblua54' (no such file)
(terminated at launch; ignore backtrace)

Thread 0 Crashed:
0   dyld                                0x7ff810c39c52 __abort_with_payload + 10
1   dyld                                0x7ff810c53fd7 abort_with_payload_wrapper_internal + 82
2   dyld                                0x7ff810c54009 abort_with_payload + 9
3   dyld                                0x7ff810bd88f0 dyld4::halt(char const*) + 375
4   dyld                                0x7ff810bd5b71 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 4526
5   dyld                                0x7ff810bd43bd start + 1805

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000002000209  rbx: 0x0000000000000000  rcx: 0x00007ff7b7406188  rdx: 0x00007ff7b74065f0
  rdi: 0x0000000000000006  rsi: 0x0000000000000001  rbp: 0x00007ff7b74061d0  rsp: 0x00007ff7b7406188
   r8: 0x00007ff7b74061f0   r9: 0x0000000000000000  r10: 0x00000000000000df  r11: 0x0000000000000246
  r12: 0x00000000000000df  r13: 0x00007ff7b74065f0  r14: 0x0000000000000001  r15: 0x0000000000000006
  rip: 0x00007ff810c39c52  rfl: 0x0000000000000246  cr2: 0x0000000000000000

Logical CPU:     0
Error Code:      0x02000209 
Trap Number:     133

Binary Images:
       0x108af8000 -        0x1091fbfff com.companyname.clearmauiluaapp (1.0) <fe058360-8185-335b-bb83-01b712f7f81b> /Users/USER/*/ClearMauiLuaApp.app/Contents/MacOS/ClearMauiLuaApp
    0x7ff810bce000 -     0x7ff810c665ef dyld (*) <3400ad17-ab59-3b27-9a44-9b280fab5c3f> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 22
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=182.5M resident=0K(0%) swapped_out_or_unallocated=182.5M(100%)
Writable regions: Total=9124K written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=9124K(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
STACK GUARD                       56.0M        1 
Stack                             8192K        1 
VM_ALLOCATE                          8K        2 
__DATA                            1323K        3 
__DATA_CONST                       148K        2 
__DATA_DIRTY                         7K        1 
__LINKEDIT                       174.9M        3 
__TEXT                            7796K        2 
dyld private memory                260K        2 
shared memory                        4K        1 
===========                     =======  ======= 
TOTAL                            248.2M       18 

-----------
Full Report
-----------

{"app_name":"ClearMauiLuaApp","timestamp":"2024-01-20 15:18:04.00 +0300","app_version":"1.0","slice_uuid":"fe058360-8185-335b-bb83-01b712f7f81b","build_version":"1","platform":6,"bundleID":"com.companyname.clearmauiluaapp","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 13.6.3 (22G436)","roots_installed":0,"name":"ClearMauiLuaApp","incident_id":"71F037E0-455F-44F2-A8BC-02E62BAAF841"}
{
  "uptime" : 67000,
  "procRole" : "Default",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro14,2",
  "coalitionID" : 1768,
  "osVersion" : {
    "train" : "macOS 13.6.3",
    "build" : "22G436",
    "releaseType" : "User"
  },
  "captureTime" : "2024-01-20 15:18:04.5168 +0300",
  "incident" : "71F037E0-455F-44F2-A8BC-02E62BAAF841",
  "pid" : 22810,
  "cpuType" : "X86-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2024-01-20 15:18:04.4785 +0300",
  "procStartAbsTime" : 67346454278182,
  "procExitAbsTime" : 67346473364605,
  "procName" : "ClearMauiLuaApp",
  "procPath" : "\/Users\/USER\/*\/ClearMauiLuaApp.app\/Contents\/MacOS\/ClearMauiLuaApp",
  "bundleInfo" : {"CFBundleShortVersionString":"1.0","CFBundleVersion":"1","CFBundleIdentifier":"com.companyname.clearmauiluaapp"},
  "storeInfo" : {"deviceIdentifierForVendor":"31733DF3-59E1-5175-B932-EEF19D840700","thirdParty":true},
  "parentProc" : "launchd",
  "parentPid" : 1,
  "coalitionName" : "com.companyname.clearmauiluaapp",
  "crashReporterKey" : "A3A6B850-4D11-D8B5-F769-235CF69CF693",
  "codeSigningID" : "com.companyname.clearmauiluaapp",
  "codeSigningTeamID" : "",
  "codeSigningFlags" : 570425345,
  "codeSigningValidationCategory" : 10,
  "codeSigningTrustLevel" : 0,
  "wakeTime" : 7034,
  "bridgeVersion" : {"build":"14Y910","train":"3.0"},
  "sleepWakeUUID" : "B7D41381-35B8-48B9-A471-96D8F2E5E9F1",
  "sip" : "enabled",
  "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"},
  "termination" : {"code":1,"flags":518,"namespace":"DYLD","indicator":"Library missing","details":["(terminated at launch; ignore backtrace)"],"reasons":["Library not loaded: @rpath\/liblua54.framework\/Versions\/A\/liblua54","Referenced from: <FE058360-8185-335B-BB83-01B712F7F81B> \/Users\/USER\/*\/ClearMauiLuaApp.app\/Contents\/MacOS\/ClearMauiLuaApp","Reason: tried: '\/Users\/yurasultanov\/Projects\/ClearMauiLuaApp\/ClearMauiLuaApp\/bin\/Debug\/net7.0-maccatalyst\/maccatalyst-x64\/ClearMauiLuaApp.app\/Contents\/Frameworks\/liblua54.framework\/Versions\/A\/liblua54' (no such file), '\/Users\/yurasultanov\/Projects\/ClearMauiLuaApp\/ClearMauiLuaApp\/bin\/Debug\/net7.0-maccatalyst\/maccatalyst-x64\/ClearMauiLuaApp.app\/Contents\/Frameworks\/liblua54.framework\/Versions\/A\/liblua54' (no such file)"]},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":22},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":744096,"threadState":{"r13":{"value":140701908100592},"rax":{"value":33554953},"rflags":{"value":582},"cpu":{"value":0},"r14":{"value":1},"rsi":{"value":1},"r8":{"value":140701908099568},"cr2":{"value":0},"rdx":{"value":140701908100592},"r10":{"value":223},"r9":{"value":0},"r15":{"value":6},"rbx":{"value":0},"trap":{"value":133},"err":{"value":33554953},"r11":{"value":582},"rip":{"value":140703409871954,"matchesCrashFrame":1},"rbp":{"value":140701908099536},"rsp":{"value":140701908099464},"r12":{"value":223},"rcx":{"value":140701908099464},"flavor":"x86_THREAD_STATE","rdi":{"value":6}},"frames":[{"imageOffset":441426,"symbol":"__abort_with_payload","symbolLocation":10,"imageIndex":1},{"imageOffset":548823,"symbol":"abort_with_payload_wrapper_internal","symbolLocation":82,"imageIndex":1},{"imageOffset":548873,"symbol":"abort_with_payload","symbolLocation":9,"imageIndex":1},{"imageOffset":43248,"symbol":"dyld4::halt(char const*)","symbolLocation":375,"imageIndex":1},{"imageOffset":31601,"symbol":"dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*)","symbolLocation":4526,"imageIndex":1},{"imageOffset":25533,"symbol":"start","symbolLocation":1805,"imageIndex":1}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4440686592,
    "CFBundleShortVersionString" : "1.0",
    "CFBundleIdentifier" : "com.companyname.clearmauiluaapp",
    "size" : 7356416,
    "uuid" : "fe058360-8185-335b-bb83-01b712f7f81b",
    "path" : "\/Users\/USER\/*\/ClearMauiLuaApp.app\/Contents\/MacOS\/ClearMauiLuaApp",
    "name" : "ClearMauiLuaApp",
    "CFBundleVersion" : "1"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703409430528,
    "size" : 624112,
    "uuid" : "3400ad17-ab59-3b27-9a44-9b280fab5c3f",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  }
],
  "sharedCache" : {
  "base" : 140703408807936,
  "size" : 21474836480,
  "uuid" : "97d6888a-2705-3991-b7e9-e38694d68f1e"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=182.5M resident=0K(0%) swapped_out_or_unallocated=182.5M(100%)\nWritable regions: Total=9124K written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=9124K(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nSTACK GUARD                       56.0M        1 \nStack                             8192K        1 \nVM_ALLOCATE                          8K        2 \n__DATA                            1323K        3 \n__DATA_CONST                       148K        2 \n__DATA_DIRTY                         7K        1 \n__LINKEDIT                       174.9M        3 \n__TEXT                            7796K        2 \ndyld private memory                260K        2 \nshared memory                        4K        1 \n===========                     =======  ======= \nTOTAL                            248.2M       18 \n",
  "legacyInfo" : {
  "threadTriggered" : {

  }
},
  "logWritingSignature" : "57838913fe96292b5eac40a0d1b4dccc630b024a",
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "62c74108bcb0435c2153f963",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "657a4921d6ad146894c1b003"
      },
      "deploymentId" : 240000394
    },
    {
      "rolloutId" : "60da5e84ab0ca017dace9abf",
      "factorPackIds" : {

      },
      "deploymentId" : 240000008
    }
  ],
  "experiments" : [

  ]
}
}

Model: MacBookPro14,2, BootROM 522.0.0.0.0, 2 processors, Dual-Core Intel Core i5, 3,1 GHz, 8 GB, SMC 2.44f6
Graphics: Intel Iris Plus Graphics 650, Intel Iris Plus Graphics 650, Built-In
Display: Color LCD, 2560 x 1600 Retina, Main, MirrorOff, Online
Memory Module: BANK 0/DIMM0, 4 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C3531324D3332443250462D3039
Memory Module: BANK 1/DIMM0, 4 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C3531324D3332443250462D3039
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x171), Broadcom BCM43xx 1.0 (7.77.111.1 AirPortDriverBrcmNIC-1772.1)
AirPort: 
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB30Bus
USB Device: Apple T1 Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.5
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.5
Jurashikku commented 8 months ago

The type of error is in pathes.

KernLua dll import

LuaLibraryName = "@rpath/liblua54.framework/liblua54"

        [DllImport(LuaLibraryName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void luaL_openlibs(lua_State luaState);

But when MAUI build it try load "@rpath/liblua54.framework/Versions/A/liblua54"

From where this "Versions/A" added?

Jurashikku commented 8 months ago

Workaround (by it's not good, and need understanding where is error in maui linker or in KernLua)

Only one way to fix this by adding trigger to project.

  1. Open $projectName.csproj as Test
  2. Add triggers to $project xmlElement <Target Name="PostBuildMaccatalyst" AfterTargets="PostBuildEvent" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'"> <Copy SourceFiles="$(TargetDir)$(TargetName).app\Contents\Frameworks\liblua54.framework\liblua54" DestinationFolder="$(TargetDir)$(TargetName).app\Contents\Frameworks\liblua54.framework\Versions\A\" /> </Target>

This action after build application copy framework to correct directory.

drasticactions commented 8 months ago

This is unrelated to the MAUI UI project and tooling. If you build a .NET Mac Catalyst app that doesn't use the MAUI UI toolkit you can replicate that crash. That makes sense because, as you point out, the path points to the wrong library. Extracting the KernLua framework from its library, and the embedded framework file does not have the versions/a path (which also makes sense) so I'm also not sure where that value is coming from, but I don't think it's anything that can be fixed in this project.

It is either most likely going to be within NLua, or xamarin-macios. @rolfbjarne What do you think?

Jurashikku commented 8 months ago

This is unrelated to the MAUI UI project and tooling. If you build a .NET Mac Catalyst app that doesn't use the MAUI UI toolkit you can replicate that crash. That makes sense because, as you point out, the path points to the wrong library. Extracting the KernLua framework from its library, and the embedded framework file does not have the versions/a path (which also makes sense) so I'm also not sure where that value is coming from, but I don't think it's anything that can be fixed in this project.

It is either most likely going to be within NLua, or xamarin-macios. @rolfbjarne What do you think?

I write ticket on NLua/KernLua too. And write all try and analizes of source (CMake and ETC) There was cmakecode

maccatalyst: ./maccatalyst/liblua54.framework/liblua54 ./maccatalyst/liblua54.framework/liblua54: xcodebuild -configuration Release -destination "platform=macOS,variant=Mac Catalyst" -project lua.maccatalyst.xcodeproj -scheme liblua54 SYMROOT=build_maccatalyst/ ditto ./build_maccatalyst/Release-maccatalyst/liblua54.framework/Versions/A/ ./maccatalyst/liblua54.framework/

Witch copy from "Versions/A" to "liblua54.framework" on xcodebuild

All in all, i don't understand where to dig, why ios and macos app try to load Version/A not simple framework folder.

ConsoleApp .net7 work correct and perfect ( in mac and windows)

Lib add by nuget package and where to fine how and why it become native is big question.

mb real question in KernLua shen try link native libe create wrong include path. I will try create something like NativeReference to avoid this error.

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
    <NativeReference Include="$(ProjectDir)libs\macos\liblua54.framework">
        <Kind>Framework</Kind>
        <SmartLink>False</SmartLink>
    </NativeReference>
</ItemGroup>

it's crutch but i'll try.

Jurashikku commented 8 months ago

So, i create forks for all products after modding Makefile with adding

ditto ./build_maccatalyst/Release-maccatalyst/liblua54.framework/Versions/A/ ./maccatalyst/liblua54.framework/Versions/A/

it's work correctly.

Now, the real problem (as i understand) that old standart of macos(or xamarin-macos) used common '/name.framework/name' path, but on new maccatalyst(or maui) it try to call '/name.framework/Versions/A/name' .

So where making linking? In Xcode or in MSBuild?

If XCode - so bab, couse all old library stop founding, couse this error. (Some libs dont need update with new os version if they selffull) But all other need wait update Makefile for buildup on prebuild action. (Like some cross platform libs from nuget (KeraLua, for example).

If MsBuild make links, mb simple add somethink like supporting old libs. (Copy '/name.framework/name' to '/name.framework/Versions/A/name' ) - that may works by hand if i copy files to 'appName.app/Frameworks/name.framework/Versions/A/name' app work correct, but drop hash of project and it's not be enable to install on local device (iphone 11, iphone 12 pro max - tests) but can debug in simulator and on mac (MacBook)

rolfbjarne commented 8 months ago

Can you zip up and attach liblua54.framework so I can have a look at it?

Jurashikku commented 8 months ago

Can you zip up and attach liblua54.framework so I can have a look at it?

Source or builded lib?

This from /obj/linker_cache/ liblua54.framework.zip

rolfbjarne commented 8 months ago

So the problem is that the library gives this location for itself (@rpath/liblua54.framework/Versions/A/liblua54):

 $ otool -l -arch arm64 liblua54.framework/liblua54 | grep LC_ID_DYLIB -A 2
          cmd LC_ID_DYLIB
      cmdsize 72
         name @rpath/liblua54.framework/Versions/A/liblua54 (offset 24)

When we ask the native linker to link in the liblua54 framework, the native linker will look at the LC_ID_DYLIB value in the framework, and then store that in the executable as the location to look for the actual library at runtime.

However, the library isn't located in Versions/A/liblua54 (of the framework), it's in the root directory of the framework (liblua54).

There are two fixes:

  1. Change the location of the liblua54 library to be where it says it is inside the .framework (in Versions/A/liblua54).
  2. Change the LC_ID_DYLIB value to state the correct location (@rpath/liblua54.framework/liblua54).

Looks like option 2. can be accomplished by setting LD_DYLIB_INSTALL_NAME in your Xcode project file: https://developer.apple.com/documentation/xcode/build-settings-reference#Dynamic-Library-Install-Name

In any case, this isn't an issue with MAUI, it's an issue with the LUA framework, so I'm going to close this.