Clang Linker 为弱符号转义 $

Clang Linker escape $ for weak symbol

我正在使用 Theos 进行调整,但我在 Makefile 和链接器标志方面遇到了问题。

链接器抱怨有一个未定义的符号,我正试图通过 -Wl,-U, _OBJC_CLASS_$_Hook_HTTestClass 来获取像这样的弱链接符号,

ARCHS = arm64

TARGET := iphone:clang:latest:7.0
INSTALL_TARGET_PROCESSES = HookTest

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = HookTestTweak

HookTestTweak_FILES = Tweak.m
HookTestTweak_CFLAGS = -fobjc-arc
HookTestTweak_LDFLAGS += -v -Wl,-U,_OBJC_CLASS_$_Hook_HTTestClass

include $(THEOS_MAKE_PATH)/tweak.mk

一开始我以为是$,所以想转义。

HookTestTweak_LDFLAGS += -v -Wl,-U,_OBJC_CLASS_$$_Hook_HTTestClass

但是链接器只是产生了这个结果(注意它是怎么说的 -U _OBJC_CLASS_),

"/home/haow6/.theos/toolchain/linux/iphone/bin/ld" -dynamic -dylib -arch arm64 -dylib_install_name /Library/MobileSubstrate/DynamicLibraries/HookTestTweak.dylib -platform_version ios 7.0.0 14.4 -multiply_defined suppress -syslibroot /home/haow6/.theos/sdks/iPhoneOS14.4.sdk -o /home/haow6/source/HookTest/HookTestTweak/.theos/obj/debug/arm64/HookTestTweak.dylib -L/home/haow6/.theos/lib -L/home/haow6/.theos/vendor/lib -lobjc -framework Foundation -framework CoreFoundation -framework CydiaSubstrate -lc++ -U _OBJC_CLASS_ /home/haow6/source/HookTest/HookTestTweak/.theos/obj/debug/arm64/Tweak.m.bd8afb95.o -lc++ -lSystem -F/home/haow6/.theos/vendor/lib
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_HTTestClass", referenced from:
      _OBJC_CLASS_$_Hook_HTTestClass in Tweak.m.bd8afb95.o
  "_OBJC_METACLASS_$_HTTestClass", referenced from:
      _OBJC_METACLASS_$_Hook_HTTestClass in Tweak.m.bd8afb95.o
ld: symbol(s) not found for architecture arm64

接下来,我尝试用引号将交易品种名称括起来,并用 -U "_OBJC_CLASS_$_Hook_HTTestClass" 更接近,但仍然不起作用,

"/home/haow6/.theos/toolchain/linux/iphone/bin/ld" -dynamic -dylib -arch arm64 -dylib_install_name /Library/MobileSubstrate/DynamicLibraries/HookTestTweak.dylib -platform_version ios 7.0.0 14.4 -multiply_defined suppress -syslibroot /home/haow6/.theos/sdks/iPhoneOS14.4.sdk -o /home/haow6/source/HookTest/HookTestTweak/.theos/obj/debug/arm64/HookTestTweak.dylib -L/home/haow6/.theos/lib -L/home/haow6/.theos/vendor/lib -lobjc -framework Foundation -framework CoreFoundation -framework CydiaSubstrate -lc++ -U "_OBJC_CLASS_$_Hook_HTTestClass" /home/haow6/source/HookTest/HookTestTweak/.theos/obj/debug/arm64/Tweak.m.bd8afb95.o -lc++ -lSystem -F/home/haow6/.theos/vendor/lib
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_HTTestClass", referenced from:
      _OBJC_CLASS_$_Hook_HTTestClass in Tweak.m.bd8afb95.o
  "_OBJC_METACLASS_$_HTTestClass", referenced from:
      _OBJC_METACLASS_$_Hook_HTTestClass in Tweak.m.bd8afb95.o
ld: symbol(s) not found for architecture arm64

我可以使用 -Wl,-undefined,dynamic_lookup 但它抱怨它已被弃用。

我希望我走在正确的轨道上,但我们将不胜感激任何帮助!

$字符是特殊的both使and成为shell,所以你必须转义两次,每次一次。

对于make,您可以通过$$将其加倍以将其转义。对于 shell,您将其包含在单引号中。所以尝试:

HookTestTweak_LDFLAGS += -v '-Wl,-U,_OBJC_CLASS_$$_Hook_HTTestClass'