我正在使用 Chris Branson 的 RedLaser MonoTouch 绑定和示例: https ://github.com/chrisbranson/RedLaserSample
首先,为了帮助那些在这个示例项目中遇到问题的人,我必须更新 makefile 以构建 RedLaser.dll MonoTouch 绑定和示例 MonoDevelop csproj 以获得实际的应用程序编译。
Makefile
Chris 提供的 makefile 解压缩了 RedLaser SDK 下载,但 RedLaser 更改了它们的命名约定,因此它不再工作。我对其进行了简化,而是要求用户手动将 libRedLaserSDK.a 文件放入构建目录:BTOUCH=/Developer/MonoTouch/usr/bin/btouch BUILDVER=build139 VERSION=3.2.4 BINDIR=./bin/ all: $(BINDIR)RedLaser.dll $(BINDIR)libRedLaserSDK.a: @echo "You'll need to obtain a copy of RedLaserDevSDK-$(VERSION).zip from" @echo "http://redlaser.com/sdk/index.php" @echo Locate the libRedLaserSDK.a file and place within @echo $(BINDIR) @echo @open http://redlaser.com/sdk/index.php @exit 1 $(BINDIR)RedLaser.dll: Makefile AssemblyInfo.cs RedLaser.cs enums.cs $(BINDIR)libRedLaserSDK.a $(BTOUCH) --out=$@ -e RedLaser.cs enums.cs AssemblyInfo.cs --link-with=$(BINDIR)libRedLaserSDK.a,libRedLaserSDK.a clean: -rm -rf $(BINDIR)*.dll
包含makefile 的目录也应该包含文件
redlaser.cs
,enums.cs
和AssemblyInfo.cs
(即与Chris 相同的)。MonoDevelop 项目构建设置
我认为这停止工作的原因是 MonoDevelop 或 MonoTouch 中的错误以及当它们包含引号时它扩展“附加 mtouch 参数”的方式。克里斯的原始论点如下所示:-cxx -gcc_flags="-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L${ProjectDir}/Lib -lRedLaserSDK -ObjC"
MonoDevelop 没有正确解析这个,而是在每个选项周围插入引号,用空格分隔。查看构建输出(在“编译为本机代码”下)表明这已扩展为:
"/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib/RedLaser.dll" -debug -nolink -sdk "5.1" -targetver "5.1" --armv7 "-cxx" "-gcc_flags=\"-framework" "SystemConfiguration" "-framework" "CFNetwork" "-framework" "CoreVideo" "-framework" "CoreMedia" "-framework" "AVFoundation" "-framework" "OpenGLES" "-framework" "Security" "-L/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib" "-lRedLaserSDK" "-ObjC\""
该解决方案包括在整个 'gcc_flags' 选项周围添加显式引号,手动转义内部引号。例如:
"-cxx" "-gcc_flags=\"-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L${ProjectDir}/Lib -lRedLaserSDK -ObjC\""
这正确地扩展为:
"/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib/RedLaser.dll" -debug -nolink -sdk "5.1" -targetver "5.1" --armv7 "-cxx" "-gcc_flags=\"-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib -lRedLaserSDK -ObjC\""
好的,所以现在我已经编译了它,我试图在我的手机上运行它。RedLaserSDK.CheckReadyStatus()
该应用程序加载正常,并通过该函数成功调用 RedLaser SDK 。但是,只要我点击扫描按钮(加载BarcodePickerController
),它就会崩溃,并在 RedLaser SDK 深处出现本机异常:
terminate called throwing an exception
Native stacktrace:
0 RedLaserSample 0x0159d62d mono_handle_native_sigsegv + 244
1 RedLaserSample 0x015b6251 sigabrt_signal_handler + 112
2 libsystem_c.dylib 0x319b67ed _sigtramp + 48
3 libsystem_c.dylib 0x319ac20f pthread_kill + 54
4 libsystem_c.dylib 0x319a529f abort + 94
5 libc++abi.dylib 0x34fb1f6b abort_message + 46
6 libc++abi.dylib 0x34faf34d _ZL17default_terminatev + 24
7 libobjc.A.dylib 0x358e536f _objc_terminate + 170
8 libc++abi.dylib 0x34faf3c5 _ZL19safe_handler_callerPFvvE + 76
9 libc++abi.dylib 0x34faf451 _ZdlPv + 0
10 libc++abi.dylib 0x34fb079f __cxa_throw + 122
11 RedLaserSample 0x000404a9 _ZN5zxing6qrcode19FinderPatternFinder18selectBestPatternsEv + 172
12 RedLaserSample 0x000415e9 _ZN5zxing6qrcode19FinderPatternFinder4findERKNS_11DecodeHintsE + 512
13 RedLaserSample 0x0003a7f7 _ZN5zxing6qrcode8Detector6detectERKNS_11DecodeHintsE + 366
14 RedLaserSample 0x00046b97 _ZN5zxing6qrcode12QRCodeReader6decodeENS_3RefINS_12BinaryBitmapEEENS_11DecodeHintsE + 130
15 RedLaserSample 0x0004ec35 _ZN5zxing6Reader6decodeENS_3RefINS_12BinaryBitmapEEE + 240
16 RedLaserSample 0x00058455 -[FormatReader decode:] + 116
17 RedLaserSample 0x00013835 -[ZXingDecoder findCodesInBitmap:bytesPerRow:width:height:] + 656
18 RedLaserSample 0x0005f6af -[BarcodePhotoEngine zxingFindBarcodesInPixmap:] + 222
19 RedLaserSample 0x00055f25 __38-[BarcodeEngine findBarcodesInPixMap:]_block_invoke_059 + 76
20 libdispatch.dylib 0x34635c59 _dispatch_call_block_and_release + 12
21 libdispatch.dylib 0x34637d0f _dispatch_queue_drain + 274
22 libdispatch.dylib 0x34637b75 _dispatch_queue_invoke$VARIANT$mp + 40
23 libdispatch.dylib 0x346387e7 _dispatch_worker_thread2 + 210
24 libsystem_c.dylib 0x31967dfb _pthread_wqthread + 294
25 libsystem_c.dylib 0x31967cd0 start_wqthread + 8
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
运行非常相似的 RedLaser Xcode 示例项目(即不涉及 MonoTouch,全部为 Objective-c)工作正常。
此外,如果它有任何意义,禁用所有条码扫描类型允许BarcodePickerController
加载和显示相机视图。显然它永远不会检测到条形码。