我正在尝试并且无法在Windows中编译此Rust code。为了完整起见,我在下面复制了它。当我做cargo build
时,我得到了:
$ cargo build
Compiling cryptominisat v5.0.1
error: failed to run custom build command for `cryptominisat v5.0.1`
process didn't exit successfully: `C:\Users\foo\Downloads\rust\target\debug\build\cryptominisat-9c79fbb9e62f2dba\build-script-build` (exit code: 101)
--- stdout
running: "cmake" "C:\\Users\\foo\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\cryptominisat-5.0.1\\cryptominisat" "-G" "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\\Users\\foo\\Downloads\\rust\\target\\debug\\build\\cryptominisat-d635308a8cbd254c\\out" "-DCMAKE_C_FLAGS= /nologo /MD" "-DCMAKE_C_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_CXX_FLAGS= /nologo /MD" "-DCMAKE_CXX_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_BUILD_TYPE=Debug"
--- stderr
CMake Error: Could not create named generator Visual Studio 14 2015 Win64
Generators
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
KDevelop3 = Generates KDevelop 3 project files.
KDevelop3 - Unix Makefiles = Generates KDevelop 3 project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
我的电脑正在运行带有Cygwin的Windows 7,我从Cygwin安装了gcc / g ++和cmake。我很乐意尝试在Windows中运行的任何其他方法。
src/main.rs
extern crate cryptominisat;
extern crate itertools;
use std::iter::once;
use cryptominisat::{Lbool, Lit, Solver};
use itertools::Itertools;
fn make_solver(n: usize) -> (Solver, Vec<Lit>) {
let mut solver = Solver::new();
let s: Vec<Lit> = (1..n).map(|_| solver.new_var()).collect();
let d: Vec<Vec<Lit>> = (1..n - 1)
.map(|k| {
(0..n - k)
.map(|i| (if i == 0 { s[k - 1] } else { solver.new_var() }))
.collect()
})
.collect();
let a: Vec<Lit> = (1..n - 1).map(|_| solver.new_var()).collect();
for k in 1..n - 1 {
for i in 1..n - k {
solver.add_xor_literal_clause(&[s[i - 1], s[k + i - 1], d[k - 1][i]], true);
}
for t in (0..n - k).combinations(2) {
solver.add_clause(&t.iter()
.map(|&i| d[k - 1][i])
.chain(once(!a[k - 1]))
.collect::<Vec<_>>()
[..]);
}
for t in (0..n - k).combinations(n - k - 1) {
solver.add_clause(&t.iter()
.map(|&i| !d[k - 1][i])
.chain(once(a[k - 1]))
.collect::<Vec<_>>()
[..]);
}
}
(solver, a)
}
fn search(n: usize,
solver: &mut Solver,
a: &Vec<Lit>,
assumptions: &mut Vec<Lit>,
k: usize)
-> usize {
match solver.solve_with_assumptions(assumptions) {
Lbool::True => search_sat(n, solver, a, assumptions, k),
Lbool::False => 0,
Lbool::Undef => panic!(),
}
}
fn search_sat(n: usize,
solver: &mut Solver,
a: &Vec<Lit>,
assumptions: &mut Vec<Lit>,
k: usize)
-> usize {
if k >= n - 1 {
1
} else {
let s = solver.is_true(a[k - 1]);
assumptions.push(if s { a[k - 1] } else { !a[k - 1] });
let c = search_sat(n, solver, a, assumptions, k + 1);
assumptions.pop();
assumptions.push(if s { !a[k - 1] } else { a[k - 1] });
let c1 = search(n, solver, a, assumptions, k + 1);
assumptions.pop();
c + c1
}
}
fn f(n: usize) -> usize {
let (mut solver, proj) = make_solver(n);
search(n, &mut solver, &proj, &mut vec![], 1)
}
fn main() {
for n in 1.. {
println!("{}: {}", n, f(n));
}
}
Cargo.toml
[package]
name = "correlations-cms"
version = "0.1.0"
authors = ["Anders Kaseorg <andersk@mit.edu>"]
[dependencies]
cryptominisat = "5.0.1"
itertools = "0.6.0"
我尝试使用rustup toolchain install stable-x86_64-pc-windows-gnu
切换工具链。现在我收到了这个错误:
$ cargo build
Compiling either v1.1.0
Compiling gcc v0.3.50
Compiling libc v0.2.23
Compiling itertools v0.6.0
Compiling cmake v0.1.24
Compiling cryptominisat v5.0.1
error: failed to run custom build command for `cryptominisat v5.0.1`
process didn't exit successfully: `C:\Users\foo\Downloads\rust\target\debug\bu ild\cryptominisat-1b603d882d3d5aef\build-script-build` (exit code: 101)
--- stdout
running: "cmake" "C:\\Users\\foo\\.cargo\\registry\\src\\github.com-1ecc6299db 9ec823\\cryptominisat-5.0.1\\cryptominisat" "-G" "MSYS Makefiles" "-DCMAKE_INSTA LL_PREFIX=C:\\Users\\foo\\Downloads\\rust\\target\\debug\\build\\cryptominisat -3d06123643d625eb\\out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -m 64" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_BUILD _TYPE=Debug"
--- stderr
CMake Error: Could not create named generator MSYS Makefiles
我现在尝试切换到使用msys2。可悲的是,这次也失败了,这次是:
/c/Users/foo/Downloads/rust
$ cargo build
Compiling cryptominisat v5.0.1
error: failed to run custom build command for `cryptominisat v5.0.1`
process didn't exit successfully: `C:\Users\foo\Downloads\rust\target\debug\build\cryptominisat-a2f1d448eae9af61\build-script-build` (exit code: 3221225477)
--- stdout
running: "cmake" "C:\\Users\\foo\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\cryptominisat-5.0.1\\cryptominisat" "-G" "MSYS Makefiles" "-DCMAKE_INSTALL_PREFIX=C:\\Users\\foo\\Downloads\\rust\\target\\debug\\build\\cryptominisat-44b3c950a6288408\\out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_BUILD_TYPE=Debug"
-- Doing a Debug build
-- Configuring incomplete, errors occurred!
--- stderr
CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_AR was not found, please set to archive program.
thread 'main' panicked at '
command did not execute successfully, got: exit code: 1
build script failed, must exit now', C:\Users\foo\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.24\src\lib.rs:593
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'main' has overflowed its stack