Mac下Tauri开发报错:symbol `_EMBED_INFO_PLIST`已定义求解决
Tauri编译错误:
_EMBED_INFO_PLIST已定义的解决方案 错误信息
error: symbol `_EMBED_INFO_PLIST` is already defined --> src/main.rs:17:14 | 17 | .run(tauri::generate_context!()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `$crate::embed_info_plist_bytes` which comes from the expansion of the macro `tauri::generate_context` (in Nightly builds, run with -Z macro-backtrace for more info) error: could not compile `sandbox` (bin "sandbox") due to 1 previous error
问题原因
你的main.rs中创建了两个独立的Tauri应用实例,并且两次调用了tauri::generate_context!()宏。该宏会将MacOS所需的Info.plist文件嵌入到二进制可执行文件中,重复调用会导致符号_EMBED_INFO_PLIST被多次定义,触发编译错误。同时,一个程序也不应该启动两个独立的Tauri应用实例。
修正后的代码
将两个命令合并到同一个Tauri Builder实例中,仅调用一次run()和generate_context!():
// Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #[tauri::command] fn greet(name: &str) -> String { format!("Hello, {}! You've been greeted from Rust!", name) } #[tauri::command] fn reply(replies: &str) -> String { format!("Your reply is {}", replies) } fn main() { tauri::Builder::default() .invoke_handler(tauri::generate_handler![greet, reply]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }
说明
tauri::generate_handler!()宏可同时接收多个命令函数,用逗号分隔即可将所有命令注册到同一个应用实例中。- 仅保留一个
run()调用,确保整个程序只启动一个Tauri应用实例,避免重复嵌入Info.plist导致的符号冲突。
内容的提问来源于stack exchange,提问作者Dallas
相关产品推荐
相关产品推荐

