Many small partners in the exploration of the bottom is often very distressed, can only rely on speculation! A little bit more flexible friends will be provided by Apple source code to help look at it, but obviously this is not too intuitive! If you can directly compile debugging, like our own code directly LLDB debugging, process tracking. That wasn’t too cool, so I compiled the current version of iOS_OBJC4-756.2

The preparatory work

If you want to experience a small partner can directly GitHub source download!

If you want to try it yourself, prepare the following conditions:

  • MAC OS 10.14
  • Xcode 10.1
  • Objc4-756.2 –

The above information is available at Apple Source.

Start the configuration

I386 architecture problem

Ios_objc4-756.2: iOS_OBJC4-756.2: iOS_OBJC4-756.2

Showing Recent Messages The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture.

Solution: Switch the values of Build Settings options in objc and objc-trampolines to Standard Architectures(64-bit Intel)

The documents are checked and filled in

‘sys/reason.h’ file not found

I have found this information for you:

  • You can go throughMaking the source codeTo download, the path isObjc 756.2 compile information/xnu - 4903.241.1 / BSD/sys/reason. H
  • Or you can passApple source 在 Xnu - 4903.241.1 / BSD/sys/reason. HPath download
  • You can also type it into Googlereason.h site:opensource.apple.comDirectional retrieval

Add the found files to the project. Such as:

  • I created one in the root directoryKCCommonfile
  • createsysfile
  • thereason.hAdd the file

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

  • choosetarget -> objc -> Build Settings
  • In the engineering ofHeader Serach PathsTo add a search path$(SRCROOT)/KCCommon

'mach-o/dyld_priv.h' file not found

'os/lock_private.h' file not found

'os/base_private.h' file not found

'pthread/tsd_private.h' file not found

'System/machine/cpu_capabilities.h' file not found

'os/tsd.h' file not found

'pthread/spinlock_private.h' file not found

'System/pthread_machdep.h' file not found

'CrashReporterClient.h' file not found

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

'_simple.h' file not found

'Block_private.h' file not found

The above error cases are handled in sum'sys/reason.h' file not foundSame solution

The loopholes in the documents are as follows:

Abnormal CrashReporterClient

If we import CrashReporterClient directly from Apple source, we still have an error:

‘CrashReporterClient.h’ file not found

Solution:

  • Need to be inBuild Settings -> Preprocessor MacrosAdd:LIBC_NO_LIBCRASHREPORTERCLIENT
  • Or download the file I gave youCrashReporterClientIn this case, we directly change the macro information inside#define LIBC_NO_LIBCRASHREPORTERCLIENT

The dyLD_PRIv file is modified

GitHub source code this is modified! What have I changed on the following board

Error: Use of unld_MACosX_version_10_13 declared identifier

Add the following macro to the top of dyLD_priv. h:

#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

Libobjc. Order path problem

Can’t open order file: / Applications/Xcode. App/Contents/Developer/Platforms/MacOSX platform/Developer/SDKs/MacOSX10.15 SDK/AppleInternal/OrderF iles/libobjc.order

  • choosetarget -> objc -> Build Settings
  • In the engineering ofOrder FileTo add a search path$(SRCROOT)/libobjc.order

LCrashReporterClient cannot be compiled

Library not found for -lCrashReporterClient

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

_objc_opt_class cannot be compiled

Undefined symbol: _objc_opt_class

This problem is due to a new system: MacOS 10.15, because at the time of writing, there is no official release yet! Here we are backwards compatible with MacOS 10.14

Xcode script compilation problems

/xcodebuild:1:1: SDK “macosx.internal” cannot be located.

/xcrun:1:1: 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)

/xcrun:1:1: unable to find utility “clang++”, not a developer tool or in PATH

  • choosetarget -> objc -> Build Phases -> Run Script(markgc)
  • Put the script textmacosx.internaltomacosx

ObjectiveC. Apinotes anomalies

no such public header file: ‘/tmp/objc.dst/usr/include/objc/ObjectiveC.apinotes’

  • choosetarget -> objc -> Build Settings
  • Text-Based InstallAPI Verification ModelTo add a search pathErrors Only

  • Other Text-Based InstallAPI FlagsClear everything

Compile successfully

Next you can Build – Build Succeeded – congratulations! 💐

You may have vomited blood all over the floor by this time! It is true that the configuration process is a little bit disgusting, especially the missing files, but we enjoy the joy of successful compilation!

Debug objC compilation

  • Create a newTarget : LGTest

  • Bind binary dependencies

  • Run code into the source code, you can freely compile debugging cough up!

conclusion

IOS will now be more of a low-level development research, tunable compilation of objC4 source code can help faster learning and easier to understand! Blog continues to update, thank you for your attention like! Blue. Blue