Visual studio 2012 带MonoTouch/Xamarin.iOS类型初始化异常/EntryPointNotFoundException的Swig
我尝试使用SWIG将非托管C++封装到XAMARI.IOS项目中。根据本教程,我已成功地将其打包到一个C#项目中: 当我尝试合并MonoTouch时,只要调用C++代码,就会总是出现运行时错误。 我知道在使用单触的SWIG时需要做一些小的调整,但我肯定错过了一些东西。我一直在关注Stephane的博客作为参考 我的C#/Monotouch项目之间的差异: 单触式Visual studio 2012 带MonoTouch/Xamarin.iOS类型初始化异常/EntryPointNotFoundException的Swig,visual-studio-2012,xamarin.ios,swig,Visual Studio 2012,Xamarin.ios,Swig,我尝试使用SWIG将非托管C++封装到XAMARI.IOS项目中。根据本教程,我已成功地将其打包到一个C#项目中: 当我尝试合并MonoTouch时,只要调用C++代码,就会总是出现运行时错误。 我知道在使用单触的SWIG时需要做一些小的调整,但我肯定错过了一些东西。我一直在关注Stephane的博客作为参考 我的C#/Monotouch项目之间的差异: 单触式 swig-csharp-c++-outdir myPath-dllimport\u Internalcpp\u file.i 然后
- swig-csharp-c++-outdir myPath-dllimport\u Internalcpp\u file.i
- 然后在我的cppinvoke.cs上运行ruby脚本(由James Moore创建)
ARGF.each do |l| case l when /public delegate void Exception(Argument)?Delegate/ puts " [MonoTouch.MonoNativeFunctionWrapper]", l when /static void SetPendingArgument(Null|OutOfRange)?Exception/ puts " [MonoTouch.MonoPInvokeCallback (typeof (ExceptionArgumentDelegate))]", l when /static void SetPending.*Exception/ puts " [MonoTouch.MonoPInvokeCallback (typeof (ExceptionDelegate))]", l when /static string CreateString/ puts " [MonoTouch.MonoPInvokeCallback (typeof (SWIGStringDelegate))]", l else puts l end end
- swig-csharp-c++-outdir myPath cpp_file.i
在StackOverflowWighwithxamarin.Application.Main(System.String[] c:\Users\joshs\Documents\Visual Studio中的args)[0x00001] 2012\Projects\stackoverflowswighwithxamarin\stackoverflowswighwithxamarin\Main.cs:17 2013-10-3114:45:48.261与Xamarin的StackOverflows[13645:21e03] 未处理的托管异常:类型引发了异常 位于的cppPINVOKE(System.TypeInitializationException)的初始值设定项 c:\Users\joshs\Documents\Visual Studio中的cpp_文件..ctor()[0x00000] 2012\Projects\stackoverflowswighwithxamarin\stackoverflowswighwithxamarin\Generated\cpp_file.cs:43 在StackOverflowWighwithXamarin.MyViewController.b_u0处 (System.Object发送方,System.EventArgs e)[0x00001]位于 c:\Users\joshs\Documents\Visual Studio 2012\Projects\stackoverflowswighwithxamarin\stackoverflowswighwithxamarin\MyViewController.cs:38 在中的MonoTouch.UIKit.UIControlEventProxy.Activated()[0x00000]处 /开发者/单点触摸/来源/单点触摸/src/UIKit/UIControl。cs:30 at (包装器管理为本机) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)位于MonoTouch.UIKit.UIApplication.Main (System.String[]参数,System.String principalClassName,System.String /Developer中的delegateClassName)[0x0004c]/ MonoTouch/Source/MonoTouch/src/UIKit/UIApplication.cs:38 at StackOverflowWithXamarin.Application.Main(System.String[]args) [0x00001]在c:\Users\joshs\Documents\Visual Studio中 2012\Projects\stackoverflowswighwithxamarin\stackoverflowswighwithxamarin\Main.cs:17 mono rt:Stacktrace: 那么,为什么我会遇到这个异常,如何修复它呢?
编辑(2013-11-1) 我的(更多/更少)完整设置: VS2012 StackOverflowWighthXamarin.sln包含两个项目
- cpp.vcxproj(C++项目)
- StackOverflowWithXamarin.csproj(由VS创建的Xamarin iOS项目(即编号xibs))
- Xamarin项目是在VS2012文件->新建->项目中创建的…->Visual C->iOS->iPad->HelloWorld应用程序
#pragma once
#ifdef cpp_EXPORTS
#define cpp_API __declspec(dllexport)
#else
#define cpp_API __declspec(dllimport)
#endif
class cpp_API cpp_file
{
public:
cpp_file(void);
~cpp_file(void);
int times2(int arg);
};
cpp_file.cpp
#include "cpp_file.h"
cpp_file::cpp_file(void)
{
}
cpp_file::~cpp_file(void)
{
}
int cpp_file::times2(int arg)
{
return arg * 2;
}
cpp_文件.i
%module cpp
%{
#include "cpp_file.h"
%}
%include <windows.i>
%include "cpp_file.h"
%cpp模块
%{
#包括“cpp_file.h”
%}
%包括
%包括“cpp_file.h”
在VS2012中,cpp_file.i文件被设置为自定义生成选项。它运行命令
swig-csharp-c++-outdir“$(SolutionDir)stackoverflowswighwithxamarin\Generated”cpp_file.i
%module cpp
%{
#include "cpp_file.h"
%}
%include <windows.i>
%include "cpp_file.h"
自定义生成工具的输出指定为:
cpp_文件_wrap.cxx
……但我从来没用过这个文件,我不知道它是干什么用的
构建我的