Apple Silicon芯片下ChakraCore引擎加载问题求解
ChakraCore适配Apple Silicon芯片的解决方案建议
错误日志
Engine name: ChakraCoreJsEngine Engine version: Nov 11, 2021 Category: Engine load error Description: Most likely it happened, because the 'libChakraCore.dylib' assembly or one of its dependencies was not found. There is no JavaScriptEngineSwitcher.ChakraCore.Native.osx-* package for the arm64 processor architecture. You can build the 'libChakraCore.dylib' assembly for the current processor architecture by using instructions from the official repository. ---> System.DllNotFoundException: Unable to load shared library 'ChakraCore' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libChakraCore, 0x0001): tried: 'libChakraCore' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibChakraCore' (no such file), '/usr/lib/libChakraCore' (no such file, not in dyld cache), 'libChakraCore' (no such file), '/usr/local/lib/libChakraCore' (not a file), '/usr/lib/libChakraCore' (no such file, not in dyld cache) at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, JsRuntime& runtime) at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsRuntime.Create(JsRuntimeAttributes attributes, JsThreadServiceCallback threadServiceCallback) at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass10_0.<.ctor>b__0() at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.ScriptTaskWithoutResult.Run()
解决方案建议
自行编译arm64架构的libChakraCore.dylib:
- 拉取ChakraCore仓库的最新代码,尽管官方Wiki停更,但社区可能有适配Apple Silicon的提交
- 在Apple Silicon设备上使用Xcode命令行工具,执行编译流程时指定arm64架构,生成适配本地芯片的动态库
- 将编译后的
libChakraCore.dylib放置到项目可加载的路径,比如项目根目录、系统库路径,或通过配置指定加载位置
替换为兼容Apple Silicon的JS引擎:
选择已有官方arm64预编译包的引擎(如V8、QuickJS),通过JavaScriptEngineSwitcher切换至对应引擎,无需自行编译适配启用Rosetta 2兼容模式:
对运行程序开启Rosetta 2兼容,让应用以x86_64架构运行,可直接使用现有x86版本的ChakraCore库,但会带来一定性能损耗
内容的提问来源于stack exchange,提问作者M. Khromov
相关产品推荐
相关产品推荐

