Error: linker 'cc' not found when cross compiling a rust project from windows to linux using cargo
I've just figured it out.
It turns out you need to tell cargo to use the LLVM linker instead. You do this by creating a new directory called .cargo
in your base directory, and then a new file called config.toml
in this directory. Here you can add the lines:
[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "linker-flavor=ld.lld"]
Then building with the command cargo build --target=x86_64-unknown-linux-musl
should work!
linker `cc` not found,
As mentioned in the message, the linker 'cc' is missing.
You can install it using apt-get
:
sudo apt-get install gcc
After the installation completes, the problem should be solved.
Linker cc not found when cross-compiling simple crate on Travis CI
Well, after experimenting and more googling, I changed my apt install command to:
sudo apt-get install -y gcc-4.8 cpp-4.8 gcc-multilib
(The first two are unmet dependencies of the third, which had to be manually installed).
Now the build runs properly.
Could not exec the linker `cc` error when running cargo build
It looks like you have installed GCC and LLVM/clang via Homebrew. Checking out the shared macOS configurations, the linker defaults to cc
. I have installed the macOS developer tools:
$ clang --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
$ cc --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
This is potentially something that Rust itself could fix, but you'd have to file a bug report / enhancement request. It's possible that you might be able to work around this by symlinking clang
as cc
, instead of just aliasing it, as aliases probably don't exist in the environment that Rust is calling out from.
error: linker `x86_64-w64-mingw32-gcc` not found
TLDR;
Besides installing a cross target with rustup you need to install an actual cross linker and tell cargo about it using cargo config file or an environment variable
It seems you are attempting to cross compile your package.
you can read here more about cross compilation;
In a nutshell compiler is a program that takes your text source code and produces something the your operating system and cpu can understand.
When you are building software for the platform you are developing on, it's all nice. You have all the tools but when you want to target another platform or os, you need a compiler that is produced to work on your machine but outputs a binary that is supposed to work on the target platform/os.
So, In your case you need to install a cross toolchain that for mac for mingw target because rust does not have a cross linker itself. Once you get a cross toolchain all you need to do is to tell cargo how to find it.
Here is a project aims to make cross compilation less painful.
I also strongly advise you to read the cargo book
here you can see one of the ways of telling cargo about the cross linker
another way is to use an environment variable (which I like better and easier to use with makefiles)
and below you can see an example of that from one of my makefiles
and Again the cargo book refers to it
Overall cross compiling is painful it took me quite some time to understand the mechanics of it but it was worth it instead of copy pasting commands I found on the blogs.
I also feel like it lacks severe documentation. Cargo book doesn't tell you anything about finding a linker assumes you know this already and pictures cross compiling as something just work out of box after installing a target toolchain with rustup.
ld: library not found for -lpq when build rust in macOS
Firstly, I run these commands:
brew install libpq
brew link --force libpq
Then:
PQ_LIB_DIR="$(brew --prefix libpq)/lib"
cargo install diesel_cli --no-default-features --features postgres
It works for me.
macOS: Big Sur 11.5
Related Topics
How to Call Accept() for One Socket from Several Threads Simultaneously
Memory Access Error Sys_Rt_Sigaction (Signal Handler)
How Do 2 or More Fork System Calls Work
Which Real-Time Priority Is the Highest Priority in Linux
Remote Linux Server to Remote Linux Server Dir Copy. How
Remove Empty Lines in a Text File via Grep
Linux Tool to Send Raw Data to a Tcp Server
Permissions Required to Move File to Different Directory in Unix/Linux
Ld_Library_Path Doesn't Seem to Work
Valgrind Does Not Work with Wsl
Diolan Dln-2 Spi Controller on X86_64 Platform
Start Jboss 7 as a Service on Linux
Linux Command Line Howto Accept Pairing for Bluetooth Device Without Pin
No Local Gulp Install Found Even After Installing Npm Install -G Gulp
Svn Error: Can't Convert String from Native Encoding to 'Utf-8'