'Library not loaded SDL2 using Xcode Version 13.3.1 on macOS 12.3.1

Am trying to learn SDL2 using Xcode Version 13.3.1 on macOS Monterey 12.3.1

Followed these steps:

  1. Downloaded/ran the dmg file and moved the extracted SDL2.framework top-level folder into /Library/Frameworks

  2. Inside Xcode, made Command line project, specifying C++ as the language.

  3. Inside Xcode's General tab, I added SDL2.framework under Frameworks and Libraries and chose for Embed as Do Not Embed

  4. Inside Xcode's Build Settings, under Search Paths / Framework Search Paths - I added the appropriate ${inherited} and ${PROJECT_DIR} (both set to non-recursive).

Now, when I try to build the project (even if I copy some introductory code, which is, for a small window rendering via an online tutorial), I get the following error:

dyld`__abort_with_payload:
    0x10005a0d4 <+0>:  movl   $0x2000209, %eax          ; imm = 0x2000209 
    0x10005a0d9 <+5>:  movq   %rcx, %r10
    0x10005a0dc <+8>:  syscall 
->  0x10005a0de <+10>: jae    0x10005a0e8               ; <+20>
    0x10005a0e0 <+12>: movq   %rax, %rdi
    0x10005a0e3 <+15>: jmp    0x100017150               ; cerror_nocancel
    0x10005a0e8 <+20>: retq   
    0x10005a0e9 <+21>: nop    
    0x10005a0ea <+22>: nop    
    0x10005a0eb <+23>: nop    

dyld[22494]: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
  Referenced from: /Users/pnwlover/Library/Developer/Xcode/DerivedData/hello_sdl-buacbgrhmffapiexkmaxsewyxqvl/Build/Products/Debug/hello_sdl
  Reason: tried: '/Users/pnwlover/Library/Developer/Xcode/DerivedData/hello_sdl-buacbgrhmffapiexkmaxsewyxqvl/Build/Products/Debug/SDL2.framework/Versions/A/SDL2' (no such file), '/Library/Frameworks/SDL2.framework/Versions/A/SDL2' (code signature in <AEE63968-5A4B-3298-93A8-8AB781F92E22> '/Library/Frameworks/SDL2.framework/Versions/A/SDL2' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Library/Frameworks/SDL2.framework/Versions/A/SDL2' (no such file)
(lldb)

What am I possibly doing wrong?



Solution 1:[1]

Check steps:

  1. Make sure the SDL2.framework is correctly imported into the project.

  2. From the log information you provided,the@rpath/SDL2.framework/Versions/A/SDL2 runtime path may be incorrect.

  3. Inside Xcode`s Build Settings, find the Runpath Search Paths option, add the real path of SDL2, or use install_name_tool to modify/add the path of SDL2.framework.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M_JSL