dyld: cannot load 'my_program' (load command 0x80000034 is unknown)

857 views Asked by At

I have a C++ program that I compile on Mac OS 13.4.1 using Cmake

One of my users has the following error: dyld: cannot load 'my_program' (load command 0x80000034 is unknown)

I have no idea why he has this error message, he is on Mac OS 10.14.6 and we both use an Intel Mac

Here are some information about the binary that might be useful:

otool -L my_program
my_program:
        /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
otool -l my_program
my_program:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __PAGEZERO
   vmaddr 0x0000000000000000
   vmsize 0x0000000100000000
  fileoff 0
 filesize 0
  maxprot 0x00000000
 initprot 0x00000000
   nsects 0
    flags 0x0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 712
  segname __TEXT
   vmaddr 0x0000000100000000
   vmsize 0x0000000001374000
  fileoff 0
 filesize 20398080
  maxprot 0x00000005
 initprot 0x00000005
   nsects 8
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000100001d00
      size 0x00000000010ae186
    offset 7424
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x00000001010afe86
      size 0x000000000000063c
    offset 17497734
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __init_offsets
   segname __TEXT
      addr 0x00000001010b04c4
      size 0x000000000000003c
    offset 17499332
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000016
 reserved1 0
 reserved2 0
Section
  sectname __gcc_except_tab
   segname __TEXT
      addr 0x00000001010b0500
      size 0x000000000001a69c
    offset 17499392
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __TEXT
      addr 0x00000001010cabc0
      size 0x000000000012f0de
    offset 17607616
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x00000001011f9ca0
      size 0x00000000000ac6f8
    offset 18848928
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x00000001012a6398
      size 0x0000000000014ef8
    offset 19555224
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x00000001012bb290
      size 0x00000000000b8d38
    offset 19640976
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 232
  segname __DATA_CONST
   vmaddr 0x0000000101374000
   vmsize 0x000000000001c000
  fileoff 20398080
 filesize 114688
  maxprot 0x00000003
 initprot 0x00000003
   nsects 2
    flags 0x10
Section
  sectname __got
   segname __DATA_CONST
      addr 0x0000000101374000
      size 0x0000000000000d78
    offset 20398080
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 266 (index into indirect symbol table)
 reserved2 0
Section
  sectname __const
   segname __DATA_CONST
      addr 0x0000000101374d80
      size 0x0000000000017b58
    offset 20401536
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 3
      cmd LC_SEGMENT_64
  cmdsize 312
  segname __DATA
   vmaddr 0x0000000101390000
   vmsize 0x0000000000034000
  fileoff 20512768
 filesize 81920
  maxprot 0x00000003
 initprot 0x00000003
   nsects 3
    flags 0x0
Section
  sectname __data
   segname __DATA
      addr 0x0000000101390000
      size 0x0000000000011050
    offset 20512768
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __bss
   segname __DATA
      addr 0x00000001013a1080
      size 0x000000000001ec48
    offset 0
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Section
  sectname __common
   segname __DATA
      addr 0x00000001013bfcd0
      size 0x00000000000007f0
    offset 0
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 4
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x00000001013c4000
   vmsize 0x00000000001b4000
  fileoff 20594688
 filesize 1772472
  maxprot 0x00000001
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 5
      cmd LC_DYLD_CHAINED_FIXUPS
  cmdsize 16
  dataoff 20594688
 datasize 25456
Load command 6
      cmd LC_DYLD_EXPORTS_TRIE
  cmdsize 16
  dataoff 20620144
 datasize 177624
Load command 7
     cmd LC_SYMTAB
 cmdsize 24
  symoff 20829768
   nsyms 29929
  stroff 21311424
 strsize 1055736
Load command 8
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 21530
     iextdefsym 21530
     nextdefsym 7957
      iundefsym 29487
      nundefsym 442
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 21308632
  nindirectsyms 697
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 9
          cmd LC_LOAD_DYLINKER
      cmdsize 32
         name /usr/lib/dyld (offset 12)
Load command 10
     cmd LC_UUID
 cmdsize 24
    uuid 482C4C59-09D1-358F-85F5-B6D96F0D359F
Load command 11
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 13.0
      sdk 13.3
   ntools 1
     tool 3
  version 857.1
Load command 12
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 13
       cmd LC_MAIN
   cmdsize 24
  entryoff 7424
 stacksize 0
Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 88
         name /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (offset 24)
   time stamp 2 Wed Dec 31 20:00:02 1969
      current version 1.0.0
compatibility version 1.0.0
Load command 15
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name /usr/lib/libc++.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 20:00:02 1969
      current version 1500.65.0
compatibility version 1.0.0
Load command 16
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 20:00:02 1969
      current version 1319.100.3
compatibility version 1.0.0
Load command 17
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 20797768
 datasize 30104
Load command 18
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 20827872
 datasize 1896
2

There are 2 answers

3
VonC On BEST ANSWER

I have no idea why he has this error message, he is on Mac OS 10.14.6 and we both use an Intel Mac

It should mean the LC_BUILD_VERSION load command (0x80000034) is not recognized on the user's Mac OS version (10.14.6) since it was introduced in later versions of macOS (before: LC_VERSION_MIN_MACOSX).

That load command is used to specify the minimum OS version on which the binary can run, as well as the SDK version used to build it.

In your CMakeLists.txt, specify a lower target macOS version that can be supported by both your development environment and your user's environment.

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)

As noted here, the FORCE parameter might be needed.

Then recompile your program.

mkdir build
cd build
cmake ..
make

And distribute the newly compiled binary to the user, for them to check if the issue persists or not.


The OP fractale adds in the comments:

I would like to add that -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 works too.
But they both generate this kind of warning if you don't build everything from source, which is annoying:

ld: warning: dylib (/usr/local/Cellar/ffmpeg/6.0_1/lib/libavcodec.dylib) 
was built for newer macOS version (13.0) than being linked (10.14)

The warning ld: warning: dylib was built for newer macOS version (13.0) than being linked (10.14) is emitted by the linker because the library libavcodec.dylib (part of the FFmpeg suite) you are linking against was built targeting a newer version of macOS (13.0) than the version you are targeting (10.14).
That could potentially cause runtime issues if the library uses features not available in macOS 10.14.

The ideal solution would be to build all your dependencies from source targeting the same macOS version you are targeting.

brew install ffmpeg --build-from-source

But, if you are confident that the newer libraries will work on the older target OS, you can suppress the linker warnings, though this is not recommended as it may mask other important warnings.

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -w")

Or, you could try and obtain and link against older versions of the libraries that were built for or are compatible with macOS 10.14.

Or, as a workaround, you could provide a script to override the dynamic library path to use older versions of the libraries.

export DYLD_LIBRARY_PATH=/path/to/older/libs:$DYLD_LIBRARY_PATH
./my_program

As noted in Richard Barber's answer, you also have the CMAKE_OSX_SYSROOT variable or -isysroot flag.

It is better to use the environment variable, to be set in the toolchain:

set(CMAKE_OSX_SYSROOT, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk)
1
Richard Barber On

To add backwards macOS compatibility, you must inform the compiler of the path to that macOS's SDK.

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk

depending on how low you want to go. The SDKs for older systems can be either found within the legacy XCode bundles, as shown above in the path, or downloaded individually from github.com/phracker (up to 11.3).