4

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

2
  • Did you solve your problem? Commented Sep 18, 2017 at 9:23
  • @Rajesh yes, see my answer below ;) Commented Sep 18, 2017 at 13:40

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

HI, and thanks for your response. The problem is that my writeHello function is written in objective-c native language, so my writeHello file is a .m, can I use the symbol "extern"?
1

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.

Comments

0

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

Comments

0

You have write the following function in your Xcode project any class extern "C" { -(void) writeHello {

} }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.