White-Oak / qml-rust

QML (Qt Quick) bindings for Rust language
MIT License
205 stars 18 forks source link

MacOS Linker failure #42

Open w4tson opened 7 years ago

w4tson commented 7 years ago

Trying to follow vandenoever's tutorial. Running Qt 5.8 on Sierra and rust 1.15.1, cmake 3.7.2

Even after setting the QTDIR64 dir to /usr/local/opt/qt5

running a cargo build gives :

cargo build -v
       Fresh libc v0.2.21
       Fresh lazy_static v0.2.2
       Fresh qml v0.0.9
   Compiling sousa v0.1.0 (file:///Users/paul/dev/sousa)
     Running `rustc --crate-name sousa src/main.rs --crate-type bin -g -C metadata=dea6be368078b2de -C extra-filename=-dea6be368078b2de --out-dir /Users/paul/dev/sousa/target/debug/deps --emit=dep-info,link -L dependency=/Users/paul/dev/sousa/target/debug/deps --extern qml=/Users/paul/dev/sousa/target/debug/deps/libqml-e187f86891a15479.rlib -L native=/Users/paul/dev/sousa/target/debug/build/qml-eb0722b0d2c5887a/out/DOtherSide/build/lib`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/paul/dev/sousa/target/debug/deps/sousa-dea6be368078b2de.0.o" "-o" "/Users/paul/dev/sousa/target/debug/deps/sousa-dea6be368078b2de" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/paul/dev/sousa/target/debug/deps" "-L" "/Users/paul/dev/sousa/target/debug/build/qml-eb0722b0d2c5887a/out/DOtherSide/build/lib" "-L" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/paul/dev/sousa/target/debug/deps/libqml-e187f86891a15479.rlib" "/Users/paul/dev/sousa/target/debug/deps/liblibc-6451aa7d8103c93e.rlib" "/Users/paul/dev/sousa/target/debug/deps/liblazy_static-13daae1d9a07c252.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-f1544d51c14ee547.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-0973ad751bdffbae.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-30637a1739b412eb.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librand-6ce8560490ee791c.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcollections-77c40ab2fac1172e.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-40208fb59386bff5.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-4b56f5c0b7251555.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-cba64299ce12485f.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_unicode-a98ebaa82aaee358.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-cfc94a4f91ad8df0.rlib" "/Users/paul/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-51cf9867f46a760f.rlib" "-l" "stdc++" "-framework" "QtCore" "-framework" "QtGui" "-framework" "QtQml" "-framework" "QtQuick" "-framework" "QtWidgets" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m"
  = note: ld: framework not found QtCore
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Also tried with a binary installation of qt 5.8, no joy there either.

thorink commented 7 years ago

Same problem here. First I thought, that Qt5 could not be found because the brew qt5 formula is keg-only and all the symlinks are missing. But a brew link qt5 --force did not help.

By the way.. I read the same tutorial 😆 .

thorink commented 7 years ago

Okay, I found a solution for this (see this SO answer).

You can create a build script which customizes the build procedure. In my case a build.rs file in the project root directory with

fn main() {
    println!("cargo:rustc-link-search=framework=/usr/local/opt/qt5/Frameworks");
}

in it and a line in the Cargo.toml file

[package]
…
build = "build.rs"

was sufficient.

thorink commented 7 years ago

Seems that additionally libc++ needs to be linked. This additional line in build.rs fixes it:

    println!("cargo:rustc-link-lib=c++");
w4tson commented 7 years ago

Awesome! Well found.

I could close this issue. However do we need something in the Readme for the future hipster trying to use this project on his/her Mac?

thorink commented 7 years ago

Maybe this would be helpfull, yes. Is this not needed in Windows/Linux?