小编dbe*_*der的帖子

为什么Rust在构建DLL时会导出整个标准库?

我正在尝试用Rust编写一个动态库,它将从现有程序加载.我需要导出一些具有特定名称和调用约定的函数.一切正常,但只要use标准库中的任何内容:

  • DLL大小气球超过3MiB(不完全漂亮,但我可以忍受)
  • 整个标准库从DLL导出.这是一个包含所有出口的列表:http://pastebin.com/LsG1u96C(5100个函数)

我错过了一些编译器开关吗?我rustc没有任何选项编译以下代码:

#![crate_type = "dylib"]
#![feature(std_misc)]

use std::ffi::CString;

#[link(name = "user32")]
#[allow(non_snake_case)]
extern "stdcall" {
    fn MessageBoxA(hWnd: u32, lpText: *const i8, lpCaption: *const i8, uType: u32) -> u32;
}

#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "stdcall" fn _AddLuaState(lua_state_ptr: u32)
{
    let info_str = format!("Lua State Created: {}!", lua_state_ptr);
    let info_cstring = CString::new(info_str).unwrap();
    let caption = CString::new("Hello from my Rust Library!").unwrap();
    MessageBoxA(0, info_cstring.as_ptr(), caption.as_ptr(), 0);
}
Run Code Online (Sandbox Code Playgroud)

_AddLuaState@4 是唯一应该导出的函数.

这是在带有rustc 1.0.0-nightly (522d09dfe …

windows dll ffi rust

13
推荐指数
1
解决办法
1250
查看次数

标签 统计

dll ×1

ffi ×1

rust ×1

windows ×1