Unity でiOS向けビルドをする際にLinkerエラー
UnityでOpenCVを使ってiOS向けにアプリを書いているのですが、
エラーでハマったので備忘録
Apple Mach-O Linker Error: Undefined symbols for architecture armv7: "_Init", referenced from: RegisterMonoModules() in RegisterMonoModules.o
のようなエラーが発生した場合
iOSProject/Libraries/RegisterMonoModules.cpp
を確認します
void RegisterMonoModules() { gEnableGyroscope = false; #if !(TARGET_IPHONE_SIMULATOR) mono_aot_only = true; mono_ficall_flag = false; mono_aot_register_module(mono_aot_module_Assembly_CSharp_info); mono_aot_register_module(mono_aot_module_UnityEngine_info); mono_aot_register_module(mono_aot_module_mscorlib_info); mono_dl_register_symbol("Init", (void*)&Init); mono_dl_register_symbol("UpdateTexture", (void*)&UpdateTexture); mono_dl_register_symbol("UnityNSObject_RetainObject", (void*)&UnityNSObject_RetainObject); mono_dl_register_symbol("UnityNSObject_ReleaseObject", (void*)&UnityNSObject_ReleaseObject); mono_dl_register_symbol("UnityNSError_Code", (void*)&UnityNSError_Code); mono_dl_register_symbol("UnityNSError_Description", (void*)&UnityNSError_Description); mono_dl_register_symbol("UnityNSError_Reason", (void*)&UnityNSError_Reason); mono_dl_register_symbol("UnityNSNotification_Name", (void*)&UnityNSNotification_Name); #endif // !(TARGET_IPHONE_SIMULATOR) }
ここの mono_dl_register_symbol("Init", (void*)&Init);
という行がイケないようです。
事実.csなファイルで以下のように行っていました。
このInitの実態はありません。
[DllImport ("__Internal")] private static extern void Init();
cppから該当のexternの行を削除した後
UnityのBuild SettingsからBuild and Runを実行しプロジェクトごとReplaceしたら正常にビルドができました。
Replaceしなくてもいいかもしれません。