编译libccrate为dylib失败。
创始人
2024-12-08 09:30:15
0

将目标类型指定为dylib。

示例代码:

从Cargo.toml导入libc crate。

[dependencies]
libc = "0.2"

在main.rs中导入库并编写程序。

extern crate libc;

fn main() {
    unsafe {
        libc::printf(b"Hello, World!\n\0".as_ptr() as *const i8);
    }
}

但在编译过程中会收到以下错误消息:

error: couldn't `cargo rustc` to build the dependencies: exit code: 1

在此之后,一个详细的错误消息将在屏幕上显示。它会告诉您特定的错误原因。

error: linking with `cc` failed: exit code: 1

  |
  = note: "cc" "-m64" "-Wl,--dynamic-linker=/usr/local/lib/libc.so" "-o" "/Users/user/project/target/debug/myapp" "/Users/user/project/target/debug/myapp.o" "-Wl,-rpath,/usr/local/lib/" "-L" "/usr/local/lib/" "-L" "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-Wl,--no-as-needed" "-l" "pthread" "-l" "System" "-l" "resolv" "-l" "util" "-l" "dl" "-l" "rt" "-l" "gcc_s.10.5" "-l" "c" "-l" "m" "-l" "core" "-l" "compiler_builtins" "-l" "nosup" "-l" "rustc_demangle" "-l" "unwind" "-l" "alloc_system" "-l" "libc" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/user/project/target/debug/deps" "-L" "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/user/project/target/debug/build/cctest-d88d03286fb51ac6/out" "-L" "/Users/user/project/target/debug/build/cctest-d88d03286fb51ac6/out/.libs"
  = note: Undefined symbols for architecture x86_64:
            "_pthread_create", referenced from:
                _main in myapp.o
            "_pthread_join", referenced from:
                _main in myapp.o
            "_strlen", referenced from:
                _main in myapp.o

相关内容

热门资讯

3分钟了解!浙江宝宝游戏辅助器... 3分钟了解!浙江宝宝游戏辅助器,中至麻将系统分配输赢,新2025版(有挂揭秘)1、下载好中至麻将系统...
六分钟了解!福建天天开心输赢规... 六分钟了解!福建天天开心输赢规律,老友十三水能不能调胜率,黑科技教程(有挂插件);1、六分钟了解!福...
2分钟了解!拱趴大菠萝吗,八闽... 2分钟了解!拱趴大菠萝吗,八闽十三水辅助,2025版教程(有挂规律)1、八闽十三水辅助透视辅助简单,...
三分钟了解!六瓣数字消有没有挂... 三分钟了解!六瓣数字消有没有挂,传送屋有挂吗,透明教程(有挂透视)1、三分钟了解!六瓣数字消有没有挂...
一分钟了解!佳友互娱有没有挂,... 一分钟了解!佳友互娱有没有挂,吉祥手机麻将助赢软件,解密教程(有挂秘籍)1、吉祥手机麻将助赢软件机器...
4分钟了解!临沧麻将有挂吗,拱... 4分钟了解!临沧麻将有挂吗,拱趴游戏有辅助器吗,介绍教程(有挂机密)1)拱趴游戏有辅助器吗辅助挂:进...
十分钟了解!财神十三张辅助,欢... 十分钟了解!财神十三张辅助,欢乐茶馆辅助器是真的吗,透明挂教程(有挂攻略)1、上手简单,内置详细流程...
2分钟了解!颍河竞技麻将有挂吗... 2分钟了解!颍河竞技麻将有挂吗,衡阳字牌免费辅助器,软件教程(有挂实操)1、任何衡阳字牌免费辅助器a...
七分钟了解!大众互娱麻将软挂神... 七分钟了解!大众互娱麻将软挂神器,心悦踢坑棋牌有挂吗,切实教程(有挂教程);1.大众互娱麻将软挂神器...
2分钟了解!熊猫四川麻将输赢规... 2分钟了解!熊猫四川麻将输赢规律,雀友会潮汕麻将有挂吗,扑克教程(有挂秘笈);一、雀友会潮汕麻将有挂...