< 返回版块

Aqrun 发表于 2018-01-21 09:39

Tags:rust cc ld

编译出错求救

dependency

//Cargo.toml
[dependencies]
diesel = { version = "1.1.1", features = ["mysql"] }
dotenv = "0.10"

source code

extern crate diesel;

use diesel::prelude::*;

fn establish_connection () -> MysqlConnection {
    let database_url = "mysql://root:root@127.0.0.1:3306/demo";
    let conn = MysqlConnection::establish(database_url).unwrap();
    conn.execute("DROP TABLE IF EXISTS users CASCADE").unwrap();

    conn
}

fn main(){
    let conn = establish_connection();
    conn.execute(r#"
        CREATE TABLE users (
            id INTEGER(11) PRIMARY KEY AUTO_INCREMENT,
            name VARCHAR(255) NOT NULL
        ) CHARACTER SET utf8
        "#).unwrap();
}

compile output

cargo run --bin demo1 --verbose
       Fresh percent-encoding v1.0.1
       Fresh byteorder v1.2.1
       Fresh libc v0.2.36
       Fresh cfg-if v0.1.2
       Fresh quote v0.3.15
       Fresh unicode-normalization v0.1.5
       Fresh void v1.0.2
       Fresh unicode-xid v0.0.4
       Fresh matches v0.1.6
       Fresh regex-syntax v0.4.2
       Fresh pkg-config v0.3.9
       Fresh lazy_static v1.0.0
       Fresh utf8-ranges v1.0.0
       Fresh rustc-demangle v0.1.5
       Fresh memchr v2.0.1
       Fresh unreachable v1.0.0
       Fresh synom v0.11.3
       Fresh unicode-bidi v0.3.4
       Fresh backtrace v0.3.5
       Fresh aho-corasick v0.6.4
       Fresh thread_local v0.3.5
       Fresh syn v0.11.11
       Fresh idna v0.1.4
       Fresh error-chain v0.10.0
       Fresh regex v0.2.5
       Fresh derive-error-chain v0.10.1
       Fresh diesel_derives v1.1.0
       Fresh url v1.6.0
       Fresh mysqlclient-sys v0.2.3
       Fresh dotenv v0.10.1
       Fresh diesel v1.1.1
   Compiling mysql_demo v0.1.0 (file:///Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo)
     Running `rustc --crate-name demo1 src/bin/demo1.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f033dda2dfb33423 -C extra-filename=-f033dda2dfb33423 --out-dir /Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps -L dependency=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps --extern diesel=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libdiesel-c4fd5f5f7565696b.rlib --extern dotenv=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libdotenv-fbd34f14d492902e.rlib --extern mysql_demo=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libmysql_demo-3067257de58ca8d2.rlib`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo10.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo11.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo110.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo111.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo112.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo113.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo114.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo115.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo12.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo13.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo14.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo15.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo16.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo17.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo18.rcgu.o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.demo19.rcgu.o" "-o" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/demo1-f033dda2dfb33423.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps" "-L" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libdiesel-c4fd5f5f7565696b.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/liburl-a4d96f2b2007104e.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libbyteorder-b8d38885d957413d.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libmysqlclient_sys-8c36d94c667a9202.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libidna-f3a45a7b1afc1ff0.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libunicode_normalization-58b88ae3295fae24.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libunicode_bidi-ccf95b6b46980c22.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libmatches-5cc6e983017125a8.rlib" "/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libpercent_encoding-a536c2e31e5b426a.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-826c8d3b356e180c.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-a13e273e3b2707ec.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-f884a0c3f8f15a2d.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-fb866798267ea81a.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-2c621ea26f0e39bb.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-6f561611194f6c6a.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-d7ea7d0f1d556c7c.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_unicode-5217969f5650afe0.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-4a937f4a2d664111.rlib" "/Volumes/macdata/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-f6c69d64299ff1c7.rlib" "-l" "mysqlclient" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m"
  = note: ld: library not found for -lmysqlclient
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error

error: Could not compile `mysql_demo`.

Caused by:
  process didn't exit successfully: `rustc --crate-name demo1 src/bin/demo1.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f033dda2dfb33423 -C extra-filename=-f033dda2dfb33423 --out-dir /Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps -L dependency=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps --extern diesel=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libdiesel-c4fd5f5f7565696b.rlib --extern dotenv=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libdotenv-fbd34f14d492902e.rlib --extern mysql_demo=/Volumes/macdata/projects/rust/github.com/aqrun/mysql_demo/target/debug/deps/libmysql_demo-3067257de58ca8d2.rlib` (exit code: 101)

评论区

写评论
Mike Tang 2018-01-21 10:25

好,那就好

@Aqrun 谢谢了可以了 用的mac + docker的mysql brew install mysql 装了个本机的好了

作者 Aqrun 2018-01-21 10:04

谢谢了可以了

用的mac + docker的mysql

brew install mysql 装了个本机的好了

Mike Tang 2018-01-21 09:46

sudo apt install libmysqlclient-dev

1 共 3 条评论, 1 页