使用logify自动生成的.xm,在make的时候提示NSLog方法undeclared错误。

需求:解决make时候NSLog方法undeclared错误
**日志:
make
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building

Making all for tweak readingcrack…
==> Compiling src/PFLListenBookVC_test.xm (arm64)…
src/PFLListenBookVC_test.xm:4:181: error: use of undeclared identifier ‘NSLog’
…__unused self, SEL __unused _cmd, _Bool hasReport) { NSLog(@"-[<PFLList…
^
src/PFLListenBookVC_test.xm:5:160: error: use of undeclared identifier ‘NSLog’
…_LOGOS_SELF_CONST __unused self, SEL __unused _cmd) { NSLog(@"-[<PFLList…

我只拷贝了两个这个错误,实际凡是有NSLog的地方都报这个错误。
**代码:
.xm部分代码

  • (_Bool )hasListenFinished { %log; _Bool r = %orig; NSLog(@" = %d", r); return r; }
  • (void)setCurrentListenPageIndex:(unsigned long long )currentListenPageIndex { %log; %orig; }
  • (unsigned long long )currentListenPageIndex { %log; unsigned long long r = %orig; NSLog(@" = %llu", r); return r; }

操作步骤:
Logify 使用.h头文件自动生成的.xm 文件,已经手动去除__weak, inout, cxx_ destruct,类*替换为void *

** 任何其他描述: 无
** 环境: mac catalina,Xcode 12

import头文件

我把nic.pl自动生成的Tweak.xm文件注释去掉,make仍旧不通过,提示以下错误:

make

Making all for tweak readingcrack…
==> Preprocessing Tweak.x…
==> Preprocessing Tweak.x…
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (arm64)…
Tweak.x:15:2: error: implicitly declaring library function ‘NSLog’ with type ‘void (id, …)’ [-Werror,-Wimplicit-function-declaration]
NSLog(@"-[<ClassName: %p> messageName:%d]", self, argument);
^
Tweak.x:15:2: note: include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for ‘NSLog’
Tweak.x:18:60: error: incompatible pointer to integer conversion passing ‘void *’ to parameter of type ‘int’ [-Werror,-Wint-conversion]
_logos_orig$_ungrouped$ClassName$messageName$(self, _cmd, nil);
^~~
/Applications/Dev/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/usr/include/objc/objc.h:108:16: note: expanded from macro ‘nil’

define nil __DARWIN_NULL

           ^~~~~~~~~~~~~

/Applications/Dev/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/usr/include/sys/_types.h:52:23: note: expanded from macro ‘__DARWIN_NULL’
#define __DARWIN_NULL ((void *)0)
^~~~~~~~~~~

我感觉是哪里配置不对,原生的%log都提示出错,:(

就是make 这个自动生成的.rm

/* How to Hook with Logos
Hooks are written with syntax similar to that of an Objective-C @implementation.
You don’t need to #include <substrate.h>, it will be done automatically, as will
the generation of a class list and an automatic constructor.
*/
%hook ClassName

// Hooking a class method

  • (id)sharedInstance {
    return %orig;
    }

// Hooking an instance method with an argument.

  • (void)messageName:(int)argument {
    %log; // Write a message about this call, including its class, name and arguments, to the system log.

    %orig; // Call through to the original function with its original arguments.
    %orig(nil); // Call through to the original function with a custom argument.

    // If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
    }

// Hooking an instance method with no arguments.

  • (id)noArguments {
    %log;
    id awesome = %orig;
    [awesome doSomethingElse];

    return awesome;
    }

// Always make sure you clean up after yourself; Not doing so could have grave consequences!
%end

使用的是原来的makefile:
TARGET := iphone:clang:latest:7.0
INSTALL_TARGET_PROCESSES = SpringBoard

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = readingcrack

readingcrack_FILES = Tweak.x
readingcrack_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/tweak.mk

我说的是import头文件你给我删注释。这波操作我属实没看懂

#import <Foundation/Foundation.h> 用什么函数都要加上其声明,编译器需要

谢谢,后来编译成功了!

谢谢,我以为%log这种自带函数应该不用import什么的,后来证明还是要的。不过我估计还是哪里缺省设置漏了,还要在每个.rm文件里再import下。