Use swift static library in Unity iOS - objective-c

I have been trying to integrate my Unity game with the iOS static library that I found on Github. The library is in Swift, however, I forked the library and I provided objective-c bindings necessary to make a call from C# code.
My static library is available in my xCode project under the products tab. To use it in Unity I copy-pasted generated library from the directory available under "Reveal in file explorer" to Unity. I put my library in the Plugin directories.
When I run my game on iOS simulator via generated by Unity solution I'm getting an error:
2020-11-02 13:56:43.450062+0100 NewUnityProject[4357:59213] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$s10Foundation3URLVMn
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
2020-11-02 13:56:43.473282+0100 NewUnityProject[4357:59213] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$s10Foundation3URLVMn
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
To validate Unity support step by step I've created an objective-c static library - Untiy was able to make a call to library and I didn't get an error. After that I added swift support to my objective-c library and then I got once again a problem with flat namespace:
2020-11-02 13:37:12.848568+0100 NewUnityProject[3034:44789] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$sBOWV
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
2020-11-02 13:37:12.874398+0100 NewUnityProject[3034:44789] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$sBOWV
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/use/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
I have been trying to set different xCode flags like "Always Embed Swift Standard Libraries" or "Enable Modules" but still no luck to run my game on iOS simulator.
Any hints are very appreciated.

Related

XCode - How to include React Native libraries in Share Extension?

I'm attempting to create a Share Extension in a React Native application.
At compilation time, I'm running into the following error:
Apple Mach-O Linker Error
"_OBJC_CLASS_$_RCTRootView", referenced from:
"_OBJC_CLASS_$_RCTBundleURLProvider", referenced from:
"_RCTRegisterModule", referenced from:
Linker command failed with exit code 1
(use -v to see invocation)
I'm interpreting this error as the Share Extension is unable to find/link the associated libraries.
I've attempted to define the libraries in the Share Extension's:
General -> Frameworks and Libraries
Build Settings -> Search Paths -> Library Search Paths
The project here: https://github.com/Meandmybadself/react-native-share-starter
Versions
XCode: 11.3.1
Podfile iOS version: 11.0
react-native: 0.63.4

What is causing: Invalid input. ld: library not found for -lclang_rt.ios

I'm trying to publish an .ipa file using Adobe AIR via Animate and have started getting this error:
Invalid input.
ld: library not found for -lclang_rt.ios
Would anyone have an idea what this might be related to?
Thanks
To update the SDK you will need to copy the library libclang_rt.ios.a into your AIR SDK and place it at: [AIR_SDK]/lib/aot/lib
You can grab the library file here: https://www.dropbox.com/s/kvhk8yxxomy3tpn/libclang_rt.ios.a?dl=0
Or from your Xcode installation:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin/libclang_rt.ios.a
If you don’t do this correctly, you will see something like the following error when packaging:
ld: library not found for -lclang_rt.ios
Compilation failed while executing : ld64

CodenameOne "Undefined symbols" error when adding native library

I am trying to add the Honeywell Captuvo iOS library to my CodenameOne project as a native library. I have been through the "Generate Native Access" process and placed the .a library in the native/ios directory. However when I send the app to be built it comes back with the error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_EAAccessoryManager", referenced from:
objc-class-ref in libCaptuvoSDK.a(CaptuvoReal.o)
Many thanks
Rereading the error message it seems I missed a key detail. You need to add the ExternalAccessory.framework to your project. To do this you need to define the build hint: ios.add_libs=ExternalAccessory.framework
Original answer below:
Is the name of the .a library preceded with the lower case word lib and does it actually end with a .a. If not make sure to rename it so it abides by these constraints.
Assuming both are OK you will need to verify the library actually has the required architecture in this case arm64.
This is explained in this question: How to check if a static library is built for 64-bit?
I would just use the second suggestion: file libFileName.a
It should include arm64 among the list of supported architectures.

Qt link library (C++ mix with objective C) error

I am using Qt to build UI Application,
The Qt application supposed to link to a static library (.a file)
The library is written by C++ and Objective C (*.mm) files.
I setup the Qt project file and linked the static library, but Qt Creator always gets linking error, and error is related with the function implement on *.mm which locates in the static library.
Question:
The Qt application how to link the library?
that's pure C++ application (Qt application) link to static library with C++ and ObjectiveC mixed (.a file).
update: link error
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_QTCaptureDevice", referenced from:
objc-class-ref in libmyapi.a(myTestFunction_mac.o)
"_QTMediaTypeVideo", referenced from:
myTestFunction() in myapi.a(myTestFunction_mac.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [myApp.app/Contents/MacOS/myApp] Error 1
14:38:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project myApp (kit: Desktop Qt 5.1.0 clang 64bit)
Qt5.1 with clang, support C++11
static library myapi.a, built by Xcode4.6 without error. Only one file is myTestFunction_mac, using QTKit framework.
myApp links myapi.a, but the myTestFunction_mac.mm implantation file has linking error.
You need to add QTKit framework to your app target.
Xcode 4
Click on the project in the browser pane to the left.
Click on the target under Targets.
Click on the Summary tab.
Expand Linked Frameworks and Libraries if not expanded.
Click on the + icon and type QTKit into the search box and add QTkit.
Xcode 3
Right click on the project.
Select Add-->Existing Frameworks.
Add QTkit.

How to resolve Undefined Symbols error?

I'm getting this error
Undefined symbols:
".objc_class_name_MyClass", referenced from:
literal-pointer#__OBJC#__cls_refs#MyClass in infoViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
When referencing the static method below:
[MyClass ClickComment:self.navigationController];
MyClass is defined in a static library that I'm referencing in my app project. When I start typing "[MyClass "..., I get message hints. The app project knows MyClass exist and which methods are defined on it. Yet, I get the above error. Commenting out this call allows the project to build without error.
In the static library, I have a .h file that references all of the library's .h files. This way, the app project needs to reference only one .h file from the static library. The static library project also has an app. I use it to test the static library. I can do the above call fine. I usually see these types of errors when the static library has build a device/debug version and the app project has build simulator/debug. However, both builds are in sync.
I know there is a reference issue but I'm unsure how to resolve it. Any suggestions?
That means that the header files are found during compilation, but the linker is not aware of the static library. Make sure your static library is listed under "Targets -> YourMainTarget > Link Binary with Libraries" in the project view.
See http://developer.apple.com/tools/XCode/XCodeprojects.html