You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 23:42:15