Clang Linker escape $ for weak symbol - objective-c

I'm using Theos for a tweak but I'm having trouble with Makefiles and linker flags.
The Linker is complaining about an undefined symbol I'm so trying to pass -Wl,-U, _OBJC_CLASS_$_Hook_HTTestClass for a weakly linked symbol like this,
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
At first, I thought it was the $, so I tried to escape it.
HookTestTweak_LDFLAGS += -v -Wl,-U,_OBJC_CLASS_$$_Hook_HTTestClass
But the linker just results in this (notice how it says -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
Next, I tried to encase the symbol name in quotes, and its closer with -U "_OBJC_CLASS_\$_Hook_HTTestClass" but it still doesn't work,
"/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
I could use -Wl,-undefined,dynamic_lookup but it complains that it's deprecated.
I hope I'm on the correct track but any help would be greatly appreciated!

The $ character is special to both make and the shell, so you have to escape it twice, once for each.
For make, you double it via $$ to escape it. For the shell, you include it in single quotes. So try:
HookTestTweak_LDFLAGS += -v '-Wl,-U,_OBJC_CLASS_$$_Hook_HTTestClass'

Related

ASIHTTPREQUEST framework compile error when method is called / link error

I am trying to compile a project using the ASIHTTPREQUEST library.
I followed the directions and linked to all the necessary libraries, and I get no errors that are not compile errors... I am allowed to try to compile the project.
The problems only arise when I try to use this code in my .m
NSURL *colorURL = [NSURL URLWithString:#"http://www.colourlovers.com/api/colors?format=json"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:colorURL];
[request setDelegate:self];
[request startAsynchronous];
from this tutorial:
http://ios-blog.co.uk/tutorials/parsing-json-on-ios-with-asihttprequest-and-sbjson/
Ld /Users/johndoe/Library/Developer/Xcode/DerivedData/round5-bdubuaqrmfeeujdoabfnpkzsctpa/Build/Products/Debug-iphonesimulator/round5.app/round5 normal i386
cd /Users/johndoe/Documents/apps/iphone/corelocationtest/round5
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/johndoe/Library/Developer/Xcode/DerivedData/round5-bdubuaqrmfeeujdoabfnpkzsctpa/Build/Products/Debug-iphonesimulator -F/Users/johndoe/Library/Developer/Xcode/DerivedData/round5-bdubuaqrmfeeujdoabfnpkzsctpa/Build/Products/Debug-iphonesimulator -filelist /Users/johndoe/Library/Developer/Xcode/DerivedData/round5-bdubuaqrmfeeujdoabfnpkzsctpa/Build/Intermediates/round5.build/Debug-iphonesimulator/round5.build/Objects-normal/i386/round5.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -lz -framework CFNetwork -framework SystemConfiguration -framework MobileCoreServices -framework CoreLocation -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/johndoe/Library/Developer/Xcode/DerivedData/round5-bdubuaqrmfeeujdoabfnpkzsctpa/Build/Products/Debug-iphonesimulator/round5.app/round5
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ASIHTTPRequest", referenced from:
objc-class-ref in round5ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't understand what this error means:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ASIHTTPRequest", referenced from:
objc-class-ref in round5ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Really lost... please help!!
PS: I looked at some other threads on stack overflow but they don't reference to the same error.
never mind!!!
duplicate:
Error with iOS 5.1 when i use ASIHTTPRequest and SBJSON
"I would take a look at the Build Phases section in your Target. Under "Compile Sources", make sure you see the .m files for ASIHTTPRequest and for SBJson. Sometimes when you drag external classes into a project, even if you check the box to copy the files into your project, they don't make it into these compile sources. When you drag a file into Xcode, there is a check box to add the file to the target. If this isn't checked, the file won't make it into the Compile Sources. Delete the files and re-add them, ensuring this file is checked (or you can add the .m files manually if you'd like)."
by jmstone

Renaming Quicklook-template GeneratePreviewForURL.m causes linker error

I'm using a slightly outdated version of Xcode (4.2.1, with Apple clang version 3.0), which might be a problem, but.. this should work regardless:
I create a new Quicklook plugin project ("File > New > New Project", then "System Plugin > Quick Look Plug-in")
Then I rename GeneratePreviewForURL.c to GeneratePreviewForURL.m (as mentioned in the Apple docs)
If I try and use any Objective-C code in the file, I get errors. For example if I add the following to the GeneratePreviewForURL method:
#include <Foundation/Foundation.h> // at start of file
NSMutableDictionary *blah;
[blah setValue:#"valuething" forKey:#"keything"];
I get the following linker error:
Undefined symbols for architecture x86_64:
"_objc_msgSend", referenced from:
_GeneratePreviewForURL in GeneratePreviewForURL.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The slightly trimmed/reformmated linker command causing the problem is:
cd ~/QuicklookExample
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang
-arch x86_64 -bundle
-isysroot /Developer/SDKs/MacOSX10.7.sdk
-L/snip -F/snip -filelist /snip/QuicklookExample.LinkFileList
-mmacosx-version-min=10.7
-framework QuickLook
-framework ApplicationServices
-framework CoreServices
-framework CoreFoundation
-o /snip/QuicklookExample
You have to add at least Foundation framework to the linked libraries.
Note that what's missing here is libobjc which should be linked directly by the fact clang should understand your code is actually Objective-C.

Xcode 4.3.3 - Error Undefined Symbols

hy all,
I am building an application to create a simple tableview, with a search bar on top to search between the elements of the table.
I have followed a tutorial and no coding errors were found, but when building, it always fails showing the following message:
Ld /Users/gouyoun/Library/Developer/Xcode/DerivedData/ERCDictionnary-atjolczeormaykcscwvnhlxdcnvk/Build/Products/Debug-iphonesimulator/ERCDictionnary.app/ERCDictionnary normal i386
cd /Users/gouyoun/Desktop/ERCDictionnary/ERCDictionnary
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Volumes/Xcode/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Volumes/Xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/gouyoun/Library/Developer/Xcode/DerivedData/ERCDictionnary-atjolczeormaykcscwvnhlxdcnvk/Build/Products/Debug-iphonesimulator -F/Users/gouyoun/Library/Developer/Xcode/DerivedData/ERCDictionnary-atjolczeormaykcscwvnhlxdcnvk/Build/Products/Debug-iphonesimulator -filelist /Users/gouyoun/Library/Developer/Xcode/DerivedData/ERCDictionnary-atjolczeormaykcscwvnhlxdcnvk/Build/Intermediates/ERCDictionnary.build/Debug-iphonesimulator/ERCDictionnary.build/Objects-normal/i386/ERCDictionnary.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/gouyoun/Library/Developer/Xcode/DerivedData/ERCDictionnary-atjolczeormaykcscwvnhlxdcnvk/Build/Products/Debug-iphonesimulator/ERCDictionnary.app/ERCDictionnary
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_OverlayViewController", referenced from:
objc-class-ref in tableView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"_OBJC_CLASS_$_OverlayViewController", referenced from:
objc-class-ref in tableView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm a newb in OBjective C, any ideas?
Your tableView class refers to a class called OverlayViewController which is not in your project.
Its done, it only needed to remove the files and re-add them later, it worked like a charm
I've had the exact same error. It occured because I had 2 xCode Projects open, an Dragged & Dropped a class from one project to the other one. I checked "Copy to project" and the files where in the new projects folder. But it crashed every time.
I deleted the classes and IMPORTED them into the project and then it worked... So be careful when using Drag'n'Drop!

mach_star framework XCode linking problems

I'm trying to build the DisposeWindow+Beep_Injector example project here: https://github.com/rentzsch/mach_star and am having trouble getting the framework it comes bundled with(mach_inject_bundle) linked to the application project correctly.
Here's the error I get:
Ld build/Development/DisposeWindow+Beep.bundle/Contents/MacOS/DisposeWindow+Beep normal x86_64
cd /Users/me/repos/mach_star/DisposeWindow+Beep
/Developer/usr/bin/llvm-gcc-4.2 -arch x86_64 -bundle -L/Users/me/repos/mach_star/DisposeWindow+Beep/build/Development -F/Users/me/repos/mach_star/DisposeWindow+Beep/build/Development -filelist /Users/me/repos/mach_star/DisposeWindow+Beep/build/DisposeWindow+Beep.build/Development/DisposeWindow+Beep.build/Objects-normal/x86_64/DisposeWindow+Beep.LinkFileList -framework Carbon -framework AudioToolbox -o /Users/me/repos/mach_star/DisposeWindow+Beep/build/Development/DisposeWindow+Beep.bundle/Contents/MacOS/DisposeWindow+Beep
Undefined symbols for architecture x86_64:
"_mach_override", referenced from:
_load in DisposeWindow+Beep.o
(maybe you meant: _mach_override_ptr)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
All the individual projects build fine but I can't build the parent project...
Here's a screenshot of what all the configs look like: http://i.imgur.com/vaLTu.png
Any ideas?
There is no mach_override, there is only a mach_override_ptr. You have to use that function.

how to compile sbopenurl (c)

im to trying to compile sbutils. it comes with a makefile but it errors out every time i try to compile it. this is the makefile:
BINS := sblaunch sburlschemes sbopenurl sbbundleids
all: $(BINS)
%: %.c ent.plist
igcc -o $# $< -std=gnu99 -framework CoreFoundation -framework SpringBoardServices
ldid -Sent.plist $#
clean:
rm -f $(BINS)
it comes with a few utils (sblaunch sburlschemes sbopenurl and sbbundleids) but i only want sbopenurl i try to complie it directly useing gcc sbopenurl but errors with
Undefined symbols:
"_CFURLCreateWithBytes", referenced from:
_main in ccMCI3Fd.o
"_SBSOpenSensitiveURLAndUnlock", referenced from:
_main in ccMCI3Fd.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
can anyone help me?
If you look at the prefixes of the symbols that the linker can't find, or if you just have look at the original Makefile, you can find out that the frameworks CoreFoundation and SpringBoardServices are neccessary. Further examination of either the sources or the Makefile will disclose that C99 extensions are used in the code therefore the -std=gnu99 flag will be needed for gcc. So compile using:
gcc -std=gnu99 -framework CoreFoundation -framework SpringBoardServices -o sbopenurl sbopenurl.c