Closed Emulator000 closed 6 years ago
That's going to depend heavily on your setup. Are you using pkg-config or mysql_config? Do you have the correct version of mysqlclient installed on your machine compiled for static linking? You mentioned you're trying to use musl -- Did you compile mysql from source against musl?
Actually I managed to resolve adding a "build.rs" file with this content:
fn main() {
println!(r"cargo:rustc-link-lib=static=mysqlclient");
println!(r"cargo:rustc-link-lib=static=stdc++");
println!(r"cargo:rustc-link-lib=static=z");
}
For everyone that is approaching this issue again, there is an update in the rustc
compiler and the previous procedure is not supported now, in order to compile statically the libmysqlclient you have to use the nighlty
compiler with the #![feature(static_nobundle)]
added in the lib.rs
or main.rs
and this is the updated build.rs
:
fn main() {
println!(r"cargo:rustc-link-lib=static=mysqlclient");
println!(r"cargo:rustc-link-lib=static-nobundle=stdc++");
println!(r"cargo:rustc-link-lib=static=z");
}
Personally I use a more complete build.rs
file as follows:
fn main() {
println!(r"cargo:rustc-link-lib=static=mysqlclient");
println!(r"cargo:rustc-link-lib=static-nobundle=stdc++");
println!(r"cargo:rustc-link-lib=static=z");
println!(r"cargo:rustc-link-lib=static=ssl");
println!(r"cargo:rustc-link-lib=static=crypto");
}
Hope that this help!
@Emulator000 And on which OS are you building this? With which dev libraries installed?
@BlackDex I'm bulding it on Ubuntu 20.04 LTS with libmysqlclient-dev
installed, I think that libmariadb-dev
it's okay too.
You can see a compiled binary in this way here: https://github.com/facile-it/rabbitmq-consumer/releases/tag/v1.0.3
How I can static link the library in order to not require the installation of "libmysqlclient.so.20" in other machines?
I tried compiling with x86_64-unknown-linux-musl without luck.