Objc4-818.2 objC4-818.2 objC4-818.2 objC4-818.2

The preparatory work

  • MAC OS 11.4
  • Xcode 12.4
  • Objc4-818.2 –
Objc4-818.2 Download address

Opensource.apple.com/ or objc opensource.apple.com/tarballs/ search

Start the configuration

Problems encountered with direct compilation

error: unable to find sdk 'macosx.internal' (in target 'objc-trampolines' from project 'objc') warning: Traditional headermap style is no longer supported; please migrate to using separate headermaps and set 'ALWAYS_SEARCH_USER_PATHS' to NO. (in target 'objc-trampolines' from project 'objc')

The solution

  • The macOS version required by the system needs to be handled

Select Target -> objc -> Build Settings -> Base SDK -> Select macOS and let the system match for you

Note: Objc and objC-trampolines need to be modified

Select Target -> objc -> Build Settings search always set ALWAYS_SEARCH_USER_PATHS to NO

Note: Objc and objC-trampolines need to be modified

Documents are checked to fill gaps

Have the following resources ready

'sys/reason.h' file not found

  • You can through the Apple the source in the xnu 7195.101.1 / BSD/sys/reason. H path to download
  • Enter the reason. You can Google h site:opensource.apple.com directional retrieval

Add the found files to the project. Such as:

  • I created one in the root directoryOSCommonfile
  • createsysfile
  • thereason.hFile in

Not yet, be sure to set a file retrieval path for our project

  • Select Target -> objc -> Build Settings
  • Add search path $(SRCROOT)/OSCommon to Header Serach Paths of the project

H 'file not found 'sys/reason.h' file not found

The omissions in the documents are as follows:

1. ‘sys/reason. H file not found xnu – 7195.101.1 / BSD/sys/reason. H download

2.’ dylD-851.27 /include/ Mach -o/ dyLD_priv. h’ file not found dylD-851.27 /include/ Mach -o/ dyLD_priv. h download

3. ‘OS/lock_private. H file not found’ OS/base_private. H ‘file not found libplatform – 220.100.1 / private/OS/lock_private. H , base_private.h (base_private.h) (version after 220.100.1 does not have this file)

4.’pthread/tsd_private.h’ file not found ‘pthread/spinlock_private.h’ file not found Libpthreads – 454.100.8 / private/pthread/tsd_private h, spinlock_private. H

5. ‘the System/machine/cpu_capabilities. H’ file not found xnu 7195.101.1 / osfmk/machine/cpu_capabilities. H

6. ‘OS/TSD. H file not found xnu – 7195.101.1 / libsyscall/OS/TSD. H

7. ‘the System/pthread_machdep. H’ file not found the latest version do not have this file, download the Libc – 825.40.1 source Libc – 825.40.1 / pthreads/pthread_machdep. H

8. ‘CrashReporterClient. H file not found the latest version do not have this file, download the Libc – 825.40 source Libc – 825.40.1 / include/CrashReporterClient. H

#include < OS /feature_private.h> // os_Feature_enabled_simple ()

10.'_simple.h' file not found

libplatform-220.100.1/private/_simple.h

11.’ OS /linker_set.h’ file not found libC-1439.100.3 / OS /linker_set.h

12.’Cambria/ traps. h’ file not found deleted

#if TARGET_OS_OSX
#include <Cambria/Traps.h>
#include <Cambria/Cambria.h>
#endif
Copy the code

13. ‘kern/restartable. H file not found xnu 7195.101.1 / osfmk/kern/restartable. H

14.'objc-shared-cache.h' file not found

dyld-851.27/include/objc-shared-cache.h

15.’objc-bp-assist.h’ file not found objc-bp-assist.h should be in objC4-818.2, but it is not officially available, so you can only comment this reference in objc-os.mm!

16.'Block_private.h' file not found

libclosure-79 –> Block_private.h

17. ‘OS/reason_private. H file not found xnu – 7195.101.1 / libkern/OS/reason_private. H

18.’ OS /variant_private.h’ file not found LIBC-1439.100.3 / OS/Reason_private. h

The lack of the library

library not found for -lCrashReporterClient

  • choosetarget -> objc -> Build Settings
  • inOther Linker FlagsRemove the-lCrashReporterClient ( DebugReleaseHave deleted)

library not found for -loah

  • choosetarget -> objc -> Build Settings
  • inOther Linker FlagsRemove the-loah ( DebugReleaseHave deleted)

Error handling

File an error
1.dyld_priv.hAn error

Remove bridgeos (3.0)

2.lock_private.hAn error

Remove bridgeos (4.0)

3. ImportCrashReporterClient.hAn error

You can solve the problem in the following ways

  • Add LIBC_NO_LIBCRASHREPORTERCLIENT in Build Settings -> Preprocessor Macros
4.variant_private.hAn error

Remove the wrong Bridgeos

5. Other errors
  1. os_feature_enabled_simple()

/ objC4-818.2 / Runtime /objc-runtime.mm:451:10: error: Feature_private. h file feature_private.h file feature_private. use of undeclared identifier ‘os_feature_enabled_simple’ if (! os_feature_enabled_simple(objc4, preoptimizedCaches, true)) { 1 error generated.

For the undeclared OS_Feature_enabled_simple () function, comment only! /// void environ_init(void) in objc-runtime.mm

//        DisablePreoptCaches = true;
//    }
Copy the code

2.Mismatch in Debug-ness Macros

Use of undeclared identifier 'oah_is_current_process_translated'
Copy the code

delete

#if TARGET_OS_OSX if (oah_is_current_process_translated()) { kern_return_t ret = objc_thread_get_rip(threads[count], (uint64_t*)&pc); if (ret ! = KERN_SUCCESS) { pc = PC_SENTINEL; } } else { pc = _get_pc_for_thread (threads[count]); } #elseCopy the code

Dyld_fall_2020_os_versions, OBJC4, preoptimizedCaches cannot be found in void environ_init(void) of objC-runtime. mm

Void environ_init(void); void environ_init(void)

5. Unrecognized macro definition dyLD_platform_version_

Dyld_platform_version_macOS_10_13! Use of undeclared identifier (LD_platform_version_) Because some files are not found, we have to use the older version of the code here, and define a few related macros in the dyLD_priv.h file:

#define DYLD_MACOSX_VERSION_10_11 0x000A0B00
#define DYLD_MACOSX_VERSION_10_12 0x000A0C00
#define DYLD_MACOSX_VERSION_10_13 0x000A0D00
#define DYLD_MACOSX_VERSION_10_14 0x000A0E00
Copy the code

The ld_program_sdk_at_least() function does not match the ld_program_sdk_at_least() function.

/// if (! dyld_program_sdk_at_least(DYLD_MACOSX_VERSION_10_13)) { if (! (dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_13)) { /// if (! dyld_program_sdk_at_least(dyld_platform_version_macOS_10_11)) { if (! (dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_11)) {Copy the code

7.NsObject.h

Use of undeclared identifier 'dyld_platform_version_bridgeOS_2_0'
Use of undeclared identifier 'dyld_platform_version_iOS_10_0'
Use of undeclared identifier 'dyld_platform_version_macOS_10_12'
Use of undeclared identifier 'dyld_platform_version_tvOS_10_0'
Use of undeclared identifier 'dyld_platform_version_watchOS_3_0'
Copy the code

Comment out the

#define sdkIsAtLeast(x, i, t, w, b) \ (dyld_program_sdk_at_least(dyld_platform_version_macOS_ ## x) || \ dyld_program_sdk_at_least(dyld_platform_version_iOS_ ## i) || \ dyld_program_sdk_at_least(dyld_platform_version_tvOS_ ##  t) || \ dyld_program_sdk_at_least(dyld_platform_version_watchOS_ ## w) || \ dyld_program_sdk_at_least(dyld_platform_version_bridgeOS_ ## b))Copy the code

Modified to

#if TARGET_OS_OSX
#   define DYLD_OS_VERSION(x, i, t, w, b) DYLD_MACOSX_VERSION_##x
#   define sdkVersion() dyld_get_program_sdk_version()

#elif TARGET_OS_IOS
#   define DYLD_OS_VERSION(x, i, t, w, b) DYLD_IOS_VERSION_##i
#   define sdkVersion() dyld_get_program_sdk_version()

#elif TARGET_OS_TV
    // dyld does not currently have distinct constants for tvOS
#   define DYLD_OS_VERSION(x, i, t, w, b) DYLD_IOS_VERSION_##t
#   define sdkVersion() dyld_get_program_sdk_version()

#elif TARGET_OS_BRIDGE
#   if TARGET_OS_WATCH
#       error bridgeOS 1.0 not supported
#   endif
    // fixme don't need bridgeOS versioning yet
#   define DYLD_OS_VERSION(x, i, t, w, b) DYLD_IOS_VERSION_##t
#   define sdkVersion() dyld_get_program_sdk_bridge_os_version()

#elif TARGET_OS_WATCH
#   define DYLD_OS_VERSION(x, i, t, w, b) DYLD_WATCHOS_VERSION_##w
    // watchOS has its own API for compatibility reasons
#   define sdkVersion() dyld_get_program_sdk_watch_os_version()

#else
#   error unknown OS
#endif

#define sdkIsOlderThan(x, i, t, w, b)                           \
            (sdkVersion() < DYLD_OS_VERSION(x, i, t, w, b))
#define sdkIsAtLeast(x, i, t, w, b)                             \
            (sdkVersion() >= DYLD_OS_VERSION(x, i, t, w, b))

// Allow bare 0 to be used in DYLD_OS_VERSION() and sdkIsOlderThan()
#define DYLD_MACOSX_VERSION_0 0
#define DYLD_IOS_VERSION_0 0
#define DYLD_TVOS_VERSION_0 0
#define DYLD_WATCHOS_VERSION_0 0
#define DYLD_BRIDGEOS_VERSION_0 0
Copy the code

8. Objc runtime – new. Mm error

'_static_assert' declared as an array with a negative size
Copy the code

Comment out the

libobjc.ordererror

can't open order file: / Applications/Xcode. App/Contents/Developer/Platforms/MacOSX platform/Developer/SDKs/MacOSX11.1 SDK/AppleInternal/OrderFi les/libobjc.orderCopy the code
  • choosetarget -> objc -> Build Settings
  • In the engineering ofOrder FileTo add a search path$(SRCROOT)/libobjc.order

Xcode script compilation problem
SDK "macosx.internal" cannot be located.
sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk macosx.internal -find clang++ 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
unable to find utility "clang++", not a developer tool or in PATH
Copy the code
  • choosetarget -> objc -> Build Phases -> Run Script(markgc)
  • Put the script textmacosx.internaltomacosx

Long breath, compiled successfully 🎉

Objc compilation debugging

  • Create a Target: Test

File -> New->Target… ->macOS->Applation->Command Line Tool

  • Bind binary dependencies

  • Run the code into the source code, you can compile and debug it freely!
Debug problems encountered

Test–Build Phases–Complie Sources

Reference: juejin. Cn/post / 684490… www.jianshu.com/p/881a70537… Blog.csdn.net/cairo123/ar…