【问题标题】:Unity Scripting armv7 ErrorUnity脚本armv7错误
【发布时间】:2014-03-20 08:36:51
【问题描述】:

我正在尝试编写我的第一个统一脚本。这是位于 Assets/Plugins 中名为 TestPlugin.cs 的文件的代码:

using UnityEngine; 
using System.Runtime.InteropServices;

public class TestPlugin : MonoBehaviour 
{
    [DllImport ("__Internal")]
    private static extern int getString ();

    public static void Awake () {
      print (getString ());
    }
} 

这是我导入到生成的 xCode 项目的 classes 文件夹中的两个文件的代码:

TestPlugin.h:

#import <Foundation/Foundation.h>

@interface TestPlugin : NSObject

-(int)getString;

@end

TestPlugin.m:

#import "TestPlugin.h"

@implementation TestPlugin

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (int)getString
{
    return 7;
}

@end

最后,这是位于 Asset 文件夹中的 javascript 文件。

TestPluginTest.js:

function Update () 
{
TestPlugin.Awake ();
}

另外,请注意,我并不一定希望这一切都能正常工作,只是在此时进行编译(尽管欢迎提供额外的指针和提示)

尝试在 iPhone(实际设备)上构建时,我在 xCode 中遇到的错误是:

架构 armv7 的未定义符号:“_getString”,已引用 从: RegisterMonoModules.o ld 中的 RegisterMonoModules():未找到架构 armv7 collect2 的符号:ld 返回 1 个退出状态

“_getString”,引用自:

RegisterMonoModules.o 中的RegisterMonoModules()

ld:未找到架构 armv7 的符号

collect2: ld 返回 1 个退出状态

我被难住了!提前致谢!

【问题讨论】:

    标签: ios unity3d


    【解决方案1】:

    我认为问题在于 Obj-C 接口,因为链接器不知道如何处理签名。当我连接一个自己编写的库时,我设计的接口只包含纯 C 代码:

    interface.h

    #ifdef __cplusplus
        extern "C" {
    #endif    
        int getString();        
    #ifdef __cplusplus
        }
    #endif
    

    interface.c:

    int getString() {
        // do something
    }
    

    也许有用的博文:

    iPhone & Unity3D: Integrating 3rd Party Static Libraries in Unity3D Generated XCode Projects

    Unity Native Plugins: OS X

    Clever Martian's Blog - An Experiment with iPhone Native UI and Unity 3 Pro

    【讨论】:

    • 所以问题是它是用objective c写的?
    • 这实际上解决了问题,但问题是我实际上需要在objective C中编写接口。不推荐这样做吗?
    • Unity 根据unity3d.com/support/documentation/Manual/Plugins.html 说不,不要误会我的意思:您当然可以在 Obj-C 中编写插件代码,但是您需要一个纯 C 中的包装器接口来进行 C#/JS 调用插件。我的库有超过 50 个类,但只有一个精简的 C 接口。
    猜你喜欢
    • 2014-01-16
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    相关资源
    最近更新 更多