2011-08-16 165 views
0

我编译了一个静态库,用于定位xcode中的“iOS设备”,并将它链接到monodouch应用程序。当我构建并运行应用程序时,我立即得到一个错误:静态库中断编译

Mono.Debugger.Soft.VMDisconnectedException: Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown. at Mono.Debugger.Soft.Connection.SendReceive (CommandSet command_set, Int32 command, Mono.Debugger.Soft.PacketWriter packet) [0x00000] in :0 at Mono.Debugger.Soft.Connection.VM_GetVersion () [0x00000] in :0 at Mono.Debugger.Soft.Connection.Connect() [0x00000] in :0 at Mono.Debugger.Soft.VirtualMachine.connect() [0x00000] in :0 at Mono.Debugger.Soft.VirtualMachineManager.ListenInternal (System.Net.Sockets.Socket dbg_sock, System.Net.Sockets.Socket con_sock) [0x00000] in :0

而且没有应用程序输出。它似乎并不重要,如果我签署或不签署库,我已经尝试过各种版本,并建立设置,甚至编译器之间切换(我使用的最后一个编译器是股票GCC 4.2编译器)。当我为模拟器构建库并将其链接到应用程序以在设备上运行时,它实际上在设备上运行,但是一旦函数被p/invoked,应用程序就退出并且我得到系统输出解释该销售无法解决。

这个不运行的原因可能是因为构建设置或某个地方,因为它运行在模拟器上它可能是JIT与AOT问题。

编辑:

这是事物的C#方:我应该提到

 [DllImport("__Internal")] 
     private static extern int CreateWorld(b2Vec2 grav, OnIOSContact startContact, ContactOver endContact); 

    delegate bool OnIOSContact(MyCollisionEvent ev); 
    delegate bool ContactOver(MyCollisionEvent ev); 

    [MonoTouch.MonoPInvokeCallback(typeof(OnIOSContact))] 
    static bool StatContactStart(MyCollisionEvent ev){...} 

    [MonoTouch.MonoPInvokeCallback(typeof(ContactOver))] 
    static bool StatContactEnd(MyCollisionEvent ev){...} 


    [StructLayout(LayoutKind.Sequential, Size=8),Serializable] 
    struct MyCollisionEvent 
    { 
     public IntPtr ActorA; 
     public IntPtr ActorB; 
    } 




    [StructLayout(LayoutKind.Sequential, Size=8),Serializable] 
    public struct b2Vec2 
    { 
     public b2Vec2(float _x, float _y) 
     { 
      x = _x; 
      y = _y; 
     } 
     public float x; 
     public float y; 
    } 

和它背后的C代码:

 extern "C" 
     int CreateWorld(b2Vec2 gravity, bool (*startContact)(Contact), bool (*endContact)(Contact)) 

//contact struct to match MyCollisionEvent in C# code 
typedef struct 
{ 
    b2Body *bodyA; 
    b2Body *bodyB; 
}Contact; 

/// A 2D column vector. 
struct b2Vec2 
{ 
    /// Default constructor does nothing (for performance). 
    b2Vec2() {} 

    /// Construct using coordinates. 
    b2Vec2(float32 x, float32 y) : x(x), y(y) {} 

    /// Set this vector to all zeros. 
    void SetZero() { x = 0.0f; y = 0.0f; } 

    /// Set this vector to some specified coordinates. 
    void Set(float32 x_, float32 y_) { x = x_; y = y_; } 

    /// Negate this vector. 
    b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; } 

    /// Read from and indexed element. 
    float32 operator() (int32 i) const 
    { 
     return (&x)[i]; 
    } 

    /// Write to an indexed element. 
    float32& operator() (int32 i) 
    { 
     return (&x)[i]; 
    } 

    /// Add a vector to this vector. 
    void operator += (const b2Vec2& v) 
    { 
     x += v.x; y += v.y; 
    } 

    /// Subtract a vector from this vector. 
    void operator -= (const b2Vec2& v) 
    { 
     x -= v.x; y -= v.y; 
    } 

    /// Multiply this vector by a scalar. 
    void operator *= (float32 a) 
    { 
     x *= a; y *= a; 
    } 

    /// Get the length of this vector (the norm). 
    float32 Length() const 
    { 
     return b2Sqrt(x * x + y * y); 
    } 

    /// Get the length squared. For performance, use this instead of 
    /// b2Vec2::Length (if possible). 
    float32 LengthSquared() const 
    { 
     return x * x + y * y; 
    } 

    /// Convert this vector into a unit vector. Returns the length. 
    float32 Normalize() 
    { 
     float32 length = Length(); 
     if (length < b2_epsilon) 
     { 
      return 0.0f; 
     } 
     float32 invLength = 1.0f/length; 
     x *= invLength; 
     y *= invLength; 

     return length; 
    } 

    /// Does this vector contain finite coordinates? 
    bool IsValid() const 
    { 
     return b2IsValid(x) && b2IsValid(y); 
    } 

    float32 x, y; 
}; 

编辑2这是我第一次写这篇文章的时候,但是我已经能够让应用在设备上运行几次了。通常它涉及以略微不同的构建设置(例如签署库)来修复项目/库,但是我一直无法辨别导致这些成功构建需要采取的步骤...

每次它运行崩溃了(由于不相关的错误),但即使对代码稍作修改(例如注释掉一行)也会导致同样的错误再次弹出。即使恢复线路也不会使错误消失。

+1

你可以编辑你的帖子,在C#(包括属性)和C中包含p/invoke签名吗?谢谢 – poupou

+0

完成。这就是所谓的特定功能(它也是第一个被粉饰的)。如果库是为模拟器构建的,我不确定它是否应该在设备上工作。 – tweetypi

+1

还请包括非原始类型的托管/本地定义,例如b2Vec2,联系人,OnIOSContact和ContactOver。当托管/本机表示不匹配时,您的随机崩溃很可能是由于堆栈处理不当而导致的。 – poupou

回答

0

经过很多痛苦,我决定我会在iPhone上做一个干净的iOS安装,并解决了错误。我仍然不确定是什么导致了这些错误,但是由于干净的iOS安装修复了它,我只能假设它与以前的安装有关,并且希望对于那一次安装非常具体。

1

我没有看到任何明显的。尝试采取分而治之的方法,即

  • 使用任何方法参数删除代码;然后
  • 删除一个参数(前一后)(例如,第一b2Vec2,则回调...)

,直到你达到(稳固,从来没有崩溃)的工作点。这将使一个较小的测试案例来检查:)

+0

好吧我只是再次尝试去除所有外部“C”函数和C#函数,试图调用这些外部“C”函数。只需链接lib,而不需要在代码中的任何地方调用任何函数。 我仍然遇到同样的问题。我确实发现,如果我重建了这个库,并将其拖到现有的被链接的库中,然后重新构建完整的解决方案,编译和运行该应用程序实际上就会运行,但它会抱怨无法找到文件。如果我只是不链接在它找到的文件和运行良好的lib ... – tweetypi

+0

我挖了崩溃日志和粘贴在这里:http://pastebin.com/7rYzmRBk(如果这有帮助...) – tweetypi

+0

如果C#代码不再调用库(它不应该需要更改C/C++代码),我不会看到它会如何崩溃。你可以在崩溃后象征你的崩溃报告和/或运行“/ Developer/MonoTouch/usr/bin/mtouch --logdev”(并复制/粘贴与崩溃相关的最后部分)。谢谢 – poupou