Linking with cc failed

Some errors I’ve encountered trying to compile (typically just cargo build):

...
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed...
  (several screens of linker arguments omitted)
  = note: /usr/bin/ld: cannot find -lpython3.5m
          collect2: error: ld returned 1 exit status


error: aborting due to previous error; 10 warnings emitted

This is different than linker 'cc' not found, which is a common problem just after installing Rust in WSL and should be fixed by simply running apt get install build-essential. I didn’t know that there’s actually a python3m executable to which this error message alludes, but it comes with Python. This error is caused by a missing libpython3.5-dev package (or whatever python version you’re using). Install this and it should work:

sudo apt install libpython3.5-dev

Publishing crates

cargo publish has an issue in WSL2 that yields a rather useless error:

adam@wsl:/mnt/c/Users/adam/source/repos/probably$ cargo publish
...
Uploading probably v0.2.0 (/mnt/c/Users/adam/source/repos/probably)
error: No such file or directory (os error 2)

This is caused by WSL2’s inability to access Windows mounts (since WSL2 runs in a VM unlike WSL). It can be fixed by simply copying your folder over to, say, ~, then doing a publish from that directory:

adam@wsl:/mnt/c/Users/adam/source/repos$ cp -r probably ~
adam@wsl:/mnt/c/Users/adam/source/repos$ cd ~/probably
adam@wsl:~/probably$ cargo publish
...
Uploading probably v0.2.0 (/home/adam/probably)
adam@wsl:~/probably$ 

Cross-Compiling for Windows

rustup target add x86_64-pc-windows-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
cargo build --target x86_64-pc-windows-gnu

cross might be useful to look into.