[英]Static library breaks build
I've compiled a static library targetting 'iOS Device' in xcode and have linked it to a monotouch app.我在 xcode 中编译了一个针对“iOS 设备”的 static 库,并将其链接到单点触控应用程序。 When I build and run the app I immediately get an error:
当我构建并运行应用程序时,我立即收到错误消息:
Mono.Debugger.Soft.VMDisconnectedException: Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown.
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
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
And there is no application output.并且没有应用output。 It doesn't seem to matter if I sign or don't sign the library, I've tried various versions and build settings even switching out between compilers (last compiler I used was the stock GCC 4.2 compiler).
我是否签署库似乎并不重要,我尝试了各种版本并构建设置,甚至在编译器之间切换(我使用的最后一个编译器是股票 GCC 4.2 编译器)。 Whm
什么
When I build the library for a simulator and link it to the app to run on the device it actually runs on the device, but as soon as a function is p/invoked the app quits and I get system output explaining the pinvoke was unable to be resolved.当我为模拟器构建库并将其链接到应用程序以在设备上运行时,它实际上在设备上运行,但是一旦 P/invoked function 应用程序退出,我得到系统 output 解释 pinvoke 无法得到解决。
The reason this isn't running may be because of build setting or something somewhere, since it runs on the simulator it could be a JIT vs. AOT issue.'它没有运行的原因可能是因为构建设置或某处,因为它在模拟器上运行,它可能是 JIT 与 AOT 的问题。
edit:编辑:
This is the C# side of things:这是 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;
}
and the C code behind it:以及它背后的 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;
};
Edit 2:编辑2:
I should have mentioned this when I first wrote the post but I have been able to get the app running on the device a few times.当我第一次写这篇文章时,我应该提到这一点,但我已经能够让应用程序在设备上运行几次。 Typically it involved revuilding the project/library with slightly different build settings (such as signing the library) but I haven't been able to discern the steps needed to be taken which causes these successful builds...
通常它涉及使用稍微不同的构建设置(例如签署库)重新构建项目/库,但我无法辨别导致这些成功构建所需采取的步骤......
Each time it did run it crashed out (due to unrelated bugs) but even slight modification to code (such as commenting out a line) caused the same error to pop up again.每次运行时它都会崩溃(由于不相关的错误),但即使是对代码的轻微修改(例如注释掉一行)也会导致再次弹出相同的错误。 Even restoring the line wouldn't make the error go away.
即使恢复线路也不会导致错误 go 消失。
I don't see anything obvious.我没有看到任何明显的东西。 Try a divide an conquer approach, ie
尝试分而治之的方法,即
until you reach a (solidly, never crashing) working point.直到您达到(稳固,永不崩溃)的工作点。 That will make a smaller test case to check:)
这将使检查的测试用例更小:)
After much pain I decided I'd do a clean install of iOS on the iPhone and that fixed up the errors.经过一番痛苦后,我决定在 iPhone 上全新安装 iOS 并修复错误。 I'm still not quite sure what was causing the errors but since a clean iOS install fixed it I can only assume it had something to do with the previous install and was hopefully very specific to that one install.
我仍然不太确定是什么导致了错误,但是由于干净的 iOS 安装修复了它,我只能假设它与以前的安装有关,并且希望非常具体到那个安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.