我试图证明 C 可以调用 Rust 库。它有效,但是当我监视程序的内存使用情况时,它不断变得越来越大。
货物.toml:
[lib]
name="test_ccallr"
crate-type=["cdylib"]
path = "src/lib.rs"
[dependencies]
libc = "0.2"
Run Code Online (Sandbox Code Playgroud)
C代码:
[lib]
name="test_ccallr"
crate-type=["cdylib"]
path = "src/lib.rs"
[dependencies]
libc = "0.2"
Run Code Online (Sandbox Code Playgroud)
我使用以下命令构建 C 代码:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
struct Payload_t{
char* data;
int len;
};
int show_str(char* raw, struct Payload_t *data);
int main()
{
while(1){
char * p_raw = "hlease print it !ello this is string from c, please print it !";
char * p_raw_ = "hhello this is another …Run Code Online (Sandbox Code Playgroud)