4
votes

I'm adjusting the build process of a library written in Rust. The goal is to have it compile on Windows with MSVCC. Due to some specific dependencies, I have to make sure that the correct MSVCC linker is being used, so I've set up a project-specific configuration file for Cargo with:

[target.x86_64-pc-windows-msvc]
linker = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe"

When I run cargo build now, my build-script build.rs is no longer executed. Since the script provides the paths for important libraries, the building process eventually fails.

To reproduce the problem under Windows 10 (64-bit) with Visual Studio 12, create a project as follows:

|   build.rs
|   Cargo.toml
|
+---.cargo
|       config
|
\---src
        main.rs

./build.rs:

use std::env;

fn main() {
    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    panic!("Building!");
}

./Cargo.toml:

[package]
name = "some_binary"
version = "0.1.0"
build = "build.rs"

.cargo/config:

[target.x86_64-pc-windows-msvc]
linker = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe"

src/main.rs:

fn main() {
    println!("Hello, world!");
}

When you call cargo build, linking should fail with

LINK : fatal error LNK1181: cannot open input file 'advapi32.lib'

1

1 Answers

2
votes

Update:

Currently, the stable version of Rust fails at including the proper libraries (namely the Windows SDK) when the VS linker is specified explictly. Consequently, the build-script could not be linked and building failed.

Solution:

Recent changes in the nightly have solved this problem. Just switch to the nightly or wait until it is merged to the stable version.