簡體   English   中英

Static 庫中斷構建

[英]Static library breaks build

我在 xcode 中編譯了一個針對“iOS 設備”的 static 庫,並將其鏈接到單點觸控應用程序。 當我構建並運行應用程序時,我立即收到錯誤消息:

Mono.Debugger.Soft.VMDisconnectedException:引發了“Mono.Debugger.Soft.VMDisconnectedException”類型的異常。 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

並且沒有應用output。 我是否簽署庫似乎並不重要,我嘗試了各種版本並構建設置,甚至在編譯器之間切換(我使用的最后一個編譯器是股票 GCC 4.2 編譯器)。 什么

當我為模擬器構建庫並將其鏈接到應用程序以在設備上運行時,它實際上在設備上運行,但是一旦 P/invoked function 應用程序退出,我得到系統 output 解釋 pinvoke 無法得到解決。

它沒有運行的原因可能是因為構建設置或某處,因為它在模擬器上運行,它可能是 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:

當我第一次寫這篇文章時,我應該提到這一點,但我已經能夠讓應用程序在設備上運行幾次。 通常它涉及使用稍微不同的構建設置(例如簽署庫)重新構建項目/庫,但我無法辨別導致這些成功構建所需采取的步驟......

每次運行時它都會崩潰(由於不相關的錯誤),但即使是對代碼的輕微修改(例如注釋掉一行)也會導致再次彈出相同的錯誤。 即使恢復線路也不會導致錯誤 go 消失。

我沒有看到任何明顯的東西。 嘗試分而治之的方法,即

  • 使用任何方法參數刪除代碼; 然后
  • 刪除一個(在另一個之后)參數(例如第一個 b2Vec2,然后是回調......)

直到您達到(穩固,永不崩潰)的工作點。 這將使檢查的測試用例更小:)

經過一番痛苦后,我決定在 iPhone 上全新安裝 iOS 並修復錯誤。 我仍然不太確定是什么導致了錯誤,但是由於干凈的 iOS 安裝修復了它,我只能假設它與以前的安裝有關,並且希望非常具體到那個安裝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM