Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows 7 build failed #102

Closed
e2ge opened this issue Apr 17, 2018 · 34 comments
Closed

windows 7 build failed #102

e2ge opened this issue Apr 17, 2018 · 34 comments

Comments

@e2ge
Copy link

e2ge commented Apr 17, 2018

toolchain: nightly-x86_64-pc-windows-msvc (default)
rustc 1.27.0-nightly (7360d6dd6 2018-04-15)

cargo build --release
.....
error: failed to run custom build command for openssl-sys v0.9.28
process didn't exit successfully: C:\Users\xxx\Documents\vscode\shadowsocks-rust\target\release\build\openssl-sys-58fb47c380c62ab0\build-script-build (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
cargo:rerun-if-env-changed=OPENSSL_DIR
note: vcpkg did not find openssl as libcrypto and libssl : VcpkgNotFound("No vcpkg.user.targets found. Set the VCPKG_ROOT environment variable or run 'vcpkg integrate install'")
note: vcpkg did not find openssl as ssleay32 and libeay32: VcpkgNotFound("No vcpkg.user.targets found. Set the VCPKG_ROOT environment variable or run 'vcpkg integrate install'")

--- stderr
thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this -sys crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it, you can set the OPENSSL_DIR environment variable for the
compilation process.

If you're in a situation where you think the directory should be found
automatically, please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.

$HOST = x86_64-pc-windows-msvc
$TARGET = x86_64-pc-windows-msvc
openssl-sys = 0.9.28

It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
installation. If there isn't one installed then you can try the rust-openssl
README for more information about how to download precompiled binaries of
OpenSSL:

https://github.com/sfackler/rust-openssl#windows

', C:\Users\xxx.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.28\build.rs:213:5
note: Run with RUST_BACKTRACE=1 for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed

@e2ge
Copy link
Author

e2ge commented Apr 17, 2018

安装openssl并指定了OPENSSL_DIR=C:\OpenSSL-Win64后openssl的问题解决,但是libsodium-ffi编译不过。
问题是:
Compiling libsodium-ffi v0.1.11
error: failed to run custom build command for libsodium-ffi v0.1.11
process didn't exit successfully: C:\Users\xxx\Documents\vscode\shadowsocks-rust\target\release\build\libsodium-ffi-20e72ec3a1921665\build-script-build (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=SODIUM_LIB_DIR
cargo:rerun-if-env-changed=SODIUM_STATIC
cargo:rerun-if-env-changed=SODIUM_BUILD_STATIC
Building libsodium 1.0.16 from source

--- stderr
thread 'main' panicked at '
"powershell" "-Command" "If ($PSVersionTable.PSVersion.Major -lt 4) { exit 1 }"

You must have Powershell v4.0 or greater installed.

', C:\Users\xxx.cargo\registry\src\github.com-1ecc6299db9ec823\libsodium-ffi-0.1.11\build.rs:70:9
note: Run with RUST_BACKTRACE=1 for a backtrace.

貌似是卡在Powershell版本不对,我用的是msys2,切换到win7的ps上依然提示这个错误。

@e2ge
Copy link
Author

e2ge commented Apr 18, 2018

手动下载libsodium-1.06-msvc
编译:
OPENSSL_DIR=C:\OpenSSL-Win64 OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes SODIUM_LIB_DIR=C:\libsodium-1.0.16-msvc\x64\Release\v141\static cargo build --release

libsodium-ffi可以编译通过,但是最后link出现错误:
= note: LINK : fatal error LNK1181: cannot open input file 'sodium.lib'


SODIUM_LIB_DIR=C:\libsodium-1.0.16-msvc\x64\Release\v141\static cargo build --release
单独编译libsodium-ffi发现release文件夹下面出现liblibsodium.d和liblibsodium.rlib
多了一个lib,不知道是不是这个问题。

@zonyitoo
Copy link
Collaborator

是这个问题,文件名没有按Windows的来。
但是AppVeyor上编译过了哦,你看看这个跟你的编译方法有什么不同?
https://github.com/shadowsocks/shadowsocks-rust/blob/master/appveyor.yml

@e2ge
Copy link
Author

e2ge commented Apr 18, 2018

看了你的appveyor,没感觉有什么不同。
不指定SODIUM_LIB_DIR,就提示ps版本不对,需要大于4.0
指定SODIUM_LIB_DIR,最后link错误
可能是win7的原因?appveyor可能win版本更高一些吧。

@e2ge
Copy link
Author

e2ge commented Apr 18, 2018

在win7上安装ps5.1就可以了,看来指定SODIUM_LIB_DIR不work。
ps5.1下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=54616
msys2编译命令:
OPENSSL_DIR=C:\\OpenSSL-Win64 OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release

@e2ge
Copy link
Author

e2ge commented Apr 19, 2018

在mingw64下也可以编译通过
toolchain:stable-x86_64-pc-windows-gnu
安装mingw-w64-x86_64-openssl,mingw-w64-x86_64-gcc,mingw-w64-x86_64-pkg-config
然后SODIUM_BUILD_STATIC=yes cargo build --release
开始的时候用的msys2的gcc,版本太低,总是出现gcc错误,后来发现pkg-config也必须用mingw64版,不然会报找不到lssl,lz和lcrypt

@zonyitoo
Copy link
Collaborator

确实比较复杂了……我手边没有Windows机器无法Debug...

@zonyitoo
Copy link
Collaborator

如果有能总结出来的经验能整理一下吗?我更新到Readme里

@e2ge
Copy link
Author

e2ge commented Apr 19, 2018

我稍微总结一下吧,因为我用的是win7,可能在win10系统中不会出现类似的问题。

msvc abi编译环境:vs 2015+powershell 5.1+openssl 1.1.0h
shell用msys2或cmd都可以,只需要注意%HOMEPATH%\.cargo\bin在环境变量里就可以。
ps5.1下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=54616
msys2编译命令:
OPENSSL_DIR=C:\\OpenSSL-Win64 OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release
OPENSSL_LIB_DIR=C:\\OpenSSL-Win64\lib\\VC\\static OPENSSL_LIBS=libcrypto64MT:libssl64MT OPENSSL_INCLUDE_DIR=C:\\OpenSSL-Win64\\include OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release
(cmd需要使用set)
遇到的错误和解决办法:

  1. 缺少OpenSSL(安装openssl并指定OPENSSL_DIR=C:\OpenSSL-Win64)
  2. 缺少libsodium(增加SODIUM_BUILD_STATIC=yes)
  3. libsodium-ffi编译失败,powershell版本太低(安装powershell 5.1)
  4. 手动下载libsodium并指定SODIUM_LIB_DIR=C:\libsodium-1.0.16-msvc\x64\Release\v141\static 最后会出现link错误,安装powershell 5.1后可不用指定SODIUM_LIB_DIR

gnu abi编译环境:msys2+mingw-w64-x86_64-gcc+mingw-w64-x86_64-pkg-config
openssl可以使用mingw64的,也可以用手动安装的。
mingw64版本openssl:pacman -S mingw-w64-x86_64-openssl
虽然也有mingw64的libsodium,但是不用SODIUM_BUILD_STATIC=yes仍然会报错,可能是版本太低?版本号1.0.12(重试了一遍,可以编译过,之前的错误可能是msys pkg-config的问题)
shell用mingw64,添加%HOMEPATH%\.cargo\bin到环境变量
使用mingw64的openssl库编译:
SODIUM_BUILD_STATIC=yes cargo build --release
或者
pacman -S mingw-w64-x86_64-libsodium
SODIUM_STATIC=yes cargo build --release
但是静态化openssl编译不过(OPENSSL_STATIC=yes)
rust-lang/rust#47048
https://stackoverflow.com/questions/48454201/statically-linking-curl-using-openssl-in-windows
使用手动安装openssl编译命令(可静态化openssl):
OPENSSL_DIR=C:\\OpenSSL-Win64 OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release
遇到的错误和解决办法:

  1. gcc报错(默认pacman -S gcc安装的是msys版本的gcc,版本太低,需要pacman -S mingw-w64-x86_64-gcc,pkg-config同理)
  2. 缺少lssl,lz和lcrypt(需要使用mingw-w64-x86_64-pkg-config,不是pkg-config)

冏,最后发现其实是我的msys2没有升级到最新的版本,msys2的gcc和pkg-config版本都太低了。
需要反复pacman -Syu,不过msys repo里面没有libsodium

zonyitoo added a commit that referenced this issue Apr 30, 2018
zonyitoo added a commit that referenced this issue May 15, 2018
* Add #102 link in README

* Migrating to tokio, #100

* Migrated to tokio-signal v0.2, reformatted

* Should not call tokio::spawn before tokio::run

* Build nightly and stable with different image tag

* Removed unnecessary rustup install

* Renamed version to v1.7.0-alpha

* Removed deprecated calls of Buf

* Updated dependencies

* [#106] Fixed bug, should not hold UDP connections forever

* Lower info log to debug

* Bump version to v1.7.0-alpha.2

* Implement a simple DNS relay server, bump version to v1.7.0-alpha.3

* Better logging

* Fixed build on travis

* Add elapsed time in log

* Should not exit if handler return error

* reformatted

* Add test for DNS

* Updated ssdns param

* Use `trust-dns` and impl Trait
1. Replaced `ToSocketAddrs` with `trust-dns`
2. Uses impl Trait for functions
3. Updated dependencies
4. Fixed bugs

* Bug fixed, logging crate in ssdns
@DeepAQ
Copy link

DeepAQ commented Feb 9, 2019

It seems that OpenSSL cannot be statically linked even if OPENSSL_STATIC=yes is set.
I am building under Windows Server 2016 and msvc toolchains.
Does anyone have any idea?

@e2ge
Copy link
Author

e2ge commented Feb 9, 2019

@DeepAQ
Because MSVC uses a different C++, you should specify the openssl dll of msvc version.

You should download openssl and install in a location such as C:\\OpenSSL-Win64 and compile with openssl statically like this:

OPENSSL_LIB_DIR=C:\\OpenSSL-Win64\lib\\VC\\static OPENSSL_LIBS=libcrypto64MT:libssl64MT OPENSSL_INCLUDE_DIR=C:\\OpenSSL-Win64\\include OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release

@DeepAQ
Copy link

DeepAQ commented Feb 11, 2019

@DeepAQ
Because MSVC uses a different C++, you should specify the openssl dll of msvc version.

You should download openssl and install in a location such as C:\OpenSSL-Win64 and compile with openssl statically like this:

OPENSSL_LIB_DIR=C:\OpenSSL-Win64\lib\VC\static OPENSSL_LIBS=libcrypto64MT:libssl64MT OPENSSL_INCLUDE_DIR=C:\OpenSSL-Win64\include OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release

It works. Thanks!

@bigtan
Copy link

bigtan commented Aug 7, 2019

改天写个帖子,windows上面用vcpkg辅助编译非常的方便。

@testcaoy7
Copy link

@bigtan 能大致说一下Windows下的编译过程吗?

@bigtan
Copy link

bigtan commented Aug 31, 2019

#163

@testcaoy7

@z16166
Copy link

z16166 commented Dec 9, 2019

用MSVC编译不了,找不到llvm-config和clang lib。

error: failed to run custom build command for libsodium-ffi v0.2.2

cargo:warning=couldn't execute llvm-config --prefix (error: 系统找不到指定的文件。 (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to a valid llvm-config executable

--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"', src\libcore\result.rs:1165:5

@zonyitoo
Copy link
Collaborator

zonyitoo commented Dec 10, 2019

这个找不到llvm-config的warning可以忽略,没有也可以跑

cargo:warning=couldn't execute llvm-config --prefix (error: 系统找不到指定的文件。 (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to a valid llvm-config executable

要装一个libclang

  1. 下一个llvm装上:http://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe ,然后配置一下PATH,或者让LIBCLANG_PATH指向安装的地址

  2. 如果你使用的method并不需要用到libsodium,可以直接把它关掉

    cargo build --no-default-feature --features "trust-dns aes-cfb"
    

    具体的feature可以自由指定,只要不填sodium就可以。

考虑直接用Docker编一个:https://github.com/shadowsocks/shadowsocks-rust/blob/master/build/Dockerfile.x86_64-pc-windows-gnu ,我用笔记本编译的时候应该是爆内存了没编出来,今晚有空我编一个出来放在Release里

@z16166
Copy link

z16166 commented Dec 10, 2019

用cargo build --no-default-features --features "trust-dns aes-cfb"编过去了。
能否在主页的README.md中加入windows编译步骤。

昨天折腾这个sodium搞了几个小时,连clang/llvm都从源码编译了一遍也没搞定。

@zonyitoo
Copy link
Collaborator

不同的Windows方法都不太一样,还可以用vcpkg或者apt-get的方式来装依赖

@z16166
Copy link

z16166 commented Dec 10, 2019

"官方"可以给出一个标准windows环境下的编译步骤,比如win10 x64 + MSVC 2019 + vcpkg这种具体的环境。

至于其它环境下,让编译者自己搞定。

@e2ge
Copy link
Author

e2ge commented Dec 29, 2019

我试了一下,gnu和msvc都是可以编译的。
安装LLVM:http://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe
会自动提示设置Path
安装openssl:https://slproweb.com/products/Win32OpenSSL.html

gnu的话用mingw:
OPENSSL_DIR=C:\\OpenSSL-Win64 OPENSSL_STATIC=yes SODIUM_BUILD_STATIC=yes cargo build --release

msvc用cmd:
创建一个简单的bat文件:

set "OPENSSL_LIB_DIR=C:\OpenSSL-Win64\lib\VC\static"
set "OPENSSL_LIBS=libcrypto64MT:libssl64MT"
set "OPENSSL_INCLUDE_DIR=C:\OpenSSL-Win64\include"
set "OPENSSL_STATIC=yes"
set "SODIUM_BUILD_STATIC=yes"
cargo build --release
pause

保存到shadowsocks-rust文件夹,双击就开始编译了。

@e2ge
Copy link
Author

e2ge commented Dec 29, 2019

libsodium-ffi改成了libsodium-sys,那"SODIUM_BUILD_STATIC=yes"应该没什么用了吧?

@zonyitoo
Copy link
Collaborator

libsodium-ffi改成了libsodium-sys,那"SODIUM_BUILD_STATIC=yes"应该没什么用了吧?

是的,默认会自己去尝试Build

@bigtan
Copy link

bigtan commented Dec 29, 2019

#163
直接用这个,编译非常顺畅

@zonyitoo
Copy link
Collaborator

@e2ge
Copy link
Author

e2ge commented Jan 6, 2020

@bigtan vcpkg是比较方便。最新1.8.0版本sodium改成libsodium-sys,这样的vcpkg应该就没有必要再安装静态libsodium了吧?

@zonyitoo Dockerfile使用的还是gnu abi,其实我也不清楚msvc和gnu性能上有没有差别,文件size上倒是没什么差别。说不定有人就是想用msvc呢😂

@zonyitoo
Copy link
Collaborator

zonyitoo commented Jan 6, 2020

@zonyitoo Dockerfile使用的还是gnu abi,其实我也不清楚msvc和gnu性能上有没有差别,文件size上倒是没什么差别。说不定有人就是想用msvc呢😂

因为没有办法用 Docker 编出来 msvc ABI 的 Binary。

应该差别不大,差别比较大的是 cygwin 。

@zonyitoo
Copy link
Collaborator

zonyitoo commented Feb 9, 2020

Powershell script for compiling on Windows with MSVC ABI (tested on circle-ci).

# Check compile target, 32bits or 64bits
# This requires `rustc` in `$PATH`
$TargetTriple = (rustc -Vv | Select-String -Pattern "host: (.*)" | foreach {$_.Matches.Value}).split()[-1]
if ($TargetTriple.StartsWith("x86_64-")) {
    $OpenSSLBits = "64"
} else {
    $OpenSSLBits = "32"
}
$OpenSSLVersion = "1_1_1d"
$OpenSSLFileName = "Win${OpenSSLBits}OpenSSL-${OpenSSLVersion}.exe"

# Download OpenSSL release package to the current directory
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri "http://slproweb.com/download/${OpenSSLFileName}" -OutFile "${OpenSSLFileName}"

# Install it to C:\OpenSSL
Start-Process "${OpenSSLFileName}" -ArgumentList "/SILENT /VERYSILENT /SP- /SUPPRESSMSGBOXES /DIR=C:\OpenSSL" -Wait

# Build shadowsocks-rust's release
cargo build --release

Prebuilt binaries could be found in: https://circleci.com/gh/shadowsocks/shadowsocks-rust/tree/master

@voltwu
Copy link

voltwu commented May 25, 2020

我的可以正常编译了,通过cargo可以编译,但是在Shadowsocks-android目录下,通过 gradle就编译不了。

@zonyitoo
Copy link
Collaborator

Please @Mygod @madeye check this problem.

@LuoZijun
Copy link
Contributor

@zonyitoo PR #319 应该可以避免发生这个问题。

@hw1020
Copy link

hw1020 commented Dec 10, 2020

我的可以正常编译了,通过cargo可以编译,但是在Shadowsocks-android目录下,通过 gradle就编译不了。

我也是

@zonyitoo
Copy link
Collaborator

I think it is because shadowsocks-android uses stable Rust by default.

@Kein
Copy link

Kein commented Oct 8, 2021

Compiling pin-project-lite v0.2.7
error: failed to build archive: function not supported

error: could not compile `cfg-if` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

Caused by:
  process didn't exit successfully: `rustc --crate-name cfg_if --edition=2018 D:\RUST\.cargo\registry\src\github.com-1ecc6299db9ec823\cfg-if-1.0.0\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C codegen-units=1 -C metadata=4b0100dd5a16cd2b -C extra-filename=-4b0100dd5a16cd2b --out-dir n:\shadowsocks-rust\target\release\deps -L dependency=n:\shadowsocks-rust\target\release\deps --cap-lints allow -C target-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+aes,+pclmulqdq` (exit code: 1)

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants