小编jef*_*ime的帖子

锈货物dylib澄清

我有一个Rust项目,我想作为dylib嵌入到另一个应用程序中。我已经crate_type = ["dylib"]设置了Cargo.toml,但是不确定是否应该这样做cdylib

当我构建项目时,它会按预期产生libfoo.dylibin target/debug,但查看otool -L它也会与libfoo.dylibin 链接target/debug/deps/。如果要在另一个应用程序中使用它,是否需要同时提供两个dylib?

同样,当crate类型cdylib为时,它也会产生两个dylib,但是deps中的一个将在文件名的末尾添加一个哈希值。我不确定这两种板条箱类型之间的区别是什么。

我可以只使用rustc来避免获得两个dylib,但是我想使用货物。建议将Rust作为dylib嵌入其他应用程序的推荐方式是什么?

如果那很重要,我正在macOS 10.12上使用Rust

embed macos dylib rust rust-cargo

4
推荐指数
1
解决办法
964
查看次数

Rust 中的盒子类型在没有引用时会自动释放吗?

在下面的代码中,退出“主”作用域时“box 5i”是否得到正确释放?他们的指针指南上的措辞似乎表明,当变量超出范围时,具有盒类型的变量就像自动调用“free()”一样。但是,如果您在这段代码中对“a”进行“free()”,最终只会释放堆上的“box 8i”。“a”最初指向的“box 5i”会发生什么?

fn foo(a: &mut Box<int>) {
    *a = box 8i;
}

fn main() {
    let mut a = box 5i;
    println!("{}", a); // -> "5"
    foo(&mut a);
    println!("{}", a); // -> "8"
}
Run Code Online (Sandbox Code Playgroud)

memory rust

3
推荐指数
1
解决办法
712
查看次数

Embeddable Common-Lisp asdf:defsystem返回无效的相对路径名

我正在尝试学习如何使用Common-Lisp的asdf,我有以下代码:

(asdf:defsystem example
    :serial t
    :components ((:file "first")
                 (:file "second")))
Run Code Online (Sandbox Code Playgroud)

但是,我一直收到错误:

Condition of type: SIMPLE-ERROR
Invalid relative pathname #P"first.lisp" for component ("example" "first")
Run Code Online (Sandbox Code Playgroud)

我在与这两个Lisp文件相同的目录中启动repl,但我不明白为什么会出现错误.我错过了什么?我在Windows上使用ECL

windows common-lisp asdf ecl

2
推荐指数
1
解决办法
119
查看次数

GLEW如何运作?

我目前正在Windows上学习OpenGL,有一些我不明白的东西.如果我想调用类似的函数glShaderSource,除非我链接GLEW,否则它是未定义的.但是,一旦我链接GLEW并调用glewInit,glShaderSource就会突然定义并可以使用.使用GLEW显式加载需要哪些函数,以及在初始化GLEW后自动加载哪些函数?

opengl glew

0
推荐指数
1
解决办法
151
查看次数

Rust"如果让"不工作?

我在Rust中包装libxml2作为学习Rust FFI的练习,我遇到了一些奇怪的事情.我是Rust的新手,但我相信以下内容应该有效.

main.rs我有:

mod xml;

fn main() {
    if let doc = xml::parse_file("filename") {
        doc.simple_function();
    }
}
Run Code Online (Sandbox Code Playgroud)

并且xml.rs是:

extern create libc;

use libc::{c_void, c_char, c_int, c_ushort};
use std::ffi::CString;

// There are other struct definitions I've implemented that xmlDoc
// depends on, but I'm not going to list them because I believe
// they're irrelevant

#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
#[repr(C)]
struct xmlDoc {
    // xmlDoc structure defined by the libxml2 API
}


pub struct Doc {
    ptr: *mut xmlDoc …
Run Code Online (Sandbox Code Playgroud)

rust

0
推荐指数
1
解决办法
340
查看次数

标签 统计

rust ×3

asdf ×1

common-lisp ×1

dylib ×1

ecl ×1

embed ×1

glew ×1

macos ×1

memory ×1

opengl ×1

rust-cargo ×1

windows ×1