Undefined symbol _UnitySendMessage - ios

Define a method in the .mm file
#if defined(__cplusplus)
extern "C"{
#endif
extern void UnitySendMessage(const char* obj, const char* method, const char* msg) __attribute__ ((weak));;
extern NSString* _CreateNSString (const char* string);
#if defined(__cplusplus)
}
#endif
#interface UnityAdapter ()
...
Called in #implementation UnityAdapter()
UnitySendMessage("PottingMobile", "bannerDidLoadAd", "");
I need help solving the following error:
ld: warning: Could not find auto-linked framework 'FBSDKCoreKit'
Undefined symbols for architecture armv7:
"_UnitySendMessage", referenced from:
-[UnityAdapter bannerDidLoadAd] in UnityAdapter.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
when i don't use UnitySendMessage method, everthing is ok.
I want to write a framework for bridging unit and iOS projects. When I use it in a unit packaged project, no problem. When I put the bridging file into my own framework, I will report an error. There is nothing in the framework project. Do I need to integrate unit's lib? If so, how to integrate? Can you give me a website? Thank you.

Unity is currently doing this with their library feature.
You can look at their solution.
If you need a solution now: Have a look at https://github.com/jiulongw/swift-unity. It's all automated and a good starting point, but missing the library feature.
This project shows how to make an actual library: https://github.com/forestlin1212/unity-ios-framework (But for an older Unity version and not automated)

Related

Linker Command Failed with exit code 1 (Use -v to see invocation) iOS Error

In my application I'm using a static library named ABC.a in that library in a c file named Layout.c there is a function called init(). And I linked the library to the projects and added the .h file. The program is compiled without error but while linking the function its throwing the error. Why?
Info: I've added that static library in build phases also.
And the library is built for armv7, armv7s and arm64. bitcode enabled: No and Build active architectures : NO
Example error:
Undefined symbols for architecture arm64:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
"amid_Val(float const*, int, int*, int, unsigned int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
Please help two days gone for this.
This is based on the fact that you mention that the .a file is generated from a c file. The linker error:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
indicates that the AMID_INIT definition came from a C++/Objective-C++ file - this is because C files would not have information about the parameters of the routine.
From this I was able to surmise that the library header file did not have c++ guards.
Three approaches in this case - wrap all imports of the library header file in the C++ code with something like:
extern "C" {
#import "lib.h"
}
or create a lib.hpp file, containing:
#pragma once
extern "C" {
#import "lib.h"
}
and #import 'lib.hpp' instead, or fix the lib.h file by adding the standard name mangling preventative:
… near start of lib.h:
#ifdef __cplusplus
extern "C" {
#endif
… near end of lib.h:
#ifdef __cplusplus
}
#endif
This allows you to keep using the lib.h with both C and C++ compilers by declaring that all the routines offered by lib.h are exposed using C linkage, rather than C++ linkage.

OCMVerify and Undefined symbols for architecture i386/armv7/armv7s

I am using OCMock (version 3.1.1) in my project and I am trying to use the OCMVerify macro to check if some method is called inside my object.
The problem is when I put this line:
OCMVerify([mockEngine notify]);
XCode show me the following link error (I've tried all platforms though):
Undefined symbols for architecture i386:
"OCMMakeLocation(objc_object*, char const*, int)", referenced from:
-[T009_EngineTest testPostEvent] in T009_EngineTest.o
ld: symbol(s) not found for architecture i386
I took the last version of the library from the website and I've also tried to compile it by myself.
Here is the unit test code:
Engine *mockEngine = OCMClassMock([Engine class]);
Object *obj = [[Object alloc] init];
[mockEngine startUp];
[mockEngine run];
[mockEngine postEvent:obj];
[NSThread sleepForTimeInterval:0.5];
OCMVerify([mockEngine notify]); // << THIS LINE CREATES THE LINK PROBLEM..
[mockEngine shutDown];
If I comment that line, the compiler links successfully..
It seems that that symbol is not in the library binary but I checked it was in the Xcode Compile Sources list.
Then I did a workaround... I hardcoded this line (the original code from the OCMock) into my unit test file:
OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){
return [OCMLocation locationWithTestCase:testCase file:[NSString stringWithUTF8String:fileCString] line:line];
}
And it works!
Now I want to know if there is some bug in OCMock or am I doing something wrong!
Here is the original header file declaring the external OCMakeLocation function:
https://github.com/erikdoe/ocmock/blob/master/Source/OCMock/OCMLocation.h
and here its implementation:
https://github.com/erikdoe/ocmock/blob/master/Source/OCMock/OCMLocation.m
Thanks.

iOS Math: undefined symbols fr architecture arm7

I'm getting the following error when trying to use C's math.h library:
#import <Foundation/Foundation.h>
#import <math.h>
#interface Filter : NSObject {
float cutoff;
float resonance;
float sampleRate;
float *f;
float freq;
float damp;
}
- (float)filter:(float)input;
#end
Can you tell me how I can solve this error? It seems that the min() function cannot be compiled to armv7 architectures.
Undefined symbols for architecture armv7:
"_min", referenced from:
-[Filter init] in Filter.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You are linking against a static library that is compiled for i386 or x86-64, in your specific case I think that you have referenced a library that contains min function but is not compiled for armv7 architecture, take a look at your referenced static library .
On iOS I had to use fmin() instead of min() as alex purposed. Further, i didn't even need to import math.h as Anoop said.

Undefined symbols for architecture armv7 SSZipArchive

Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_SSZipArchive", referenced from: objc-class-ref in
LoginVC.o ld: symbol(s) not found for architecture armv7 clang: error:
linker command failed with exit code 1 (use -v to see invocation)
just solved! I really tried everything, but yeah, it has catched me too now -> CMD+alt+Return, I only have to clean it, and now it works.
Be careful, if you have same problems with SSZipArchive check this:
- check the prefix.pch: You added some objective-C classes here? -->so just move it into
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
...cause minizip is compiling together with objective-classes, and thats a problem for minizip, so move it into #ifdef to work clear.
- clean baby: Just clean like me your project, if you tried many mistakes before [CMD]+[alt]+return - be careful
- add SSZipArchive not as reference: Just create your SSZipArchive to first like:
SSZipArchive
SSZipArchive.h
SSZipArchive.m
minizip(folder)
..just look also thisNiceLink..but it can work anyway as referenced folder, look here..both don't worked for me (cause I don't cleaned after experiments ;))..I have created a folder construct like above on finder, and drag drop it into my project (just click "create groups")
..so I hope it helps you.. :)

How to use iOS framework with Unity?

I'm trying to use an iOS native framework inside Unity, but I don't know how.
Inside my C# script, I call a native function like this :
[DllImport ("__Internal")]
private static extern void writeHello();
void Start () {
writeHello();
}
I have drag the iOS framework inside my project like this :
Link to my image
But when I deploy my app on iPad, xCode showing this error :
Undefined symbols for architecture armv7: "_writeHello", referenced
from:
RegisterMonoModules() in RegisterMonoModules.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with
exit code 1 (use -v to see invocation)
I don't understand why, and I don't know if what I'm trying to do is possible.
Help! :)
Thanks,
Sennin
The iOS framework must be put in the xCode generated project, not in unity.
And the framework's functions must be wrapped in an extern "C" block (as shown here).
Then you will be able to use it in C# with dllimport.
The doc says that all files with extensions .a,.m,.mm,.c,.cpp located in the Assets/Plugins/iOS folder will be merged into the generated Xcode project automatically. The docs also says that subfolders are currently not supported, so, in your example, the "framework-helloUnity.framework" folder will be ignored.
It is important to note that .m files default to C-style bindings, while .mm files default to C++-style bindings. In other word, unless you use the extern "C" keyword, as Heilo suggested, your functions won't be found if you put them in .mm or .cpp files.
In other words, if you put the following:
void writeHello() {}
in a file named Assets/Plugins/iOS/myTestFile.m, your code should compile.
Found the solution thanks to this post : Calling Objective-C method from C++ method?
By doing like that :
void myWriteHello( void *test) {
[(id)test writeHello];
}
- (void) writeHello
{
NSLog(#"Hello World!");
}
and calling my C function from Unity
You have write the following function in your Xcode project any class
extern "C"
{
-(void) writeHello
{
}
}

Resources