shadowsocks-rust icon indicating copy to clipboard operation
shadowsocks-rust copied to clipboard

windows 7 build failed

Open e2ge opened this issue 7 years ago • 34 comments
trafficstars

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 avatar Apr 17 '18 19:04 e2ge

安装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 avatar Apr 17 '18 23:04 e2ge

手动下载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,不知道是不是这个问题。

e2ge avatar Apr 18 '18 02:04 e2ge

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

zonyitoo avatar Apr 18 '18 03:04 zonyitoo

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

e2ge avatar Apr 18 '18 15:04 e2ge

在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 avatar Apr 18 '18 17:04 e2ge

在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

e2ge avatar Apr 19 '18 02:04 e2ge

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

zonyitoo avatar Apr 19 '18 03:04 zonyitoo

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

zonyitoo avatar Apr 19 '18 03:04 zonyitoo

我稍微总结一下吧,因为我用的是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) https://github.com/rust-lang/rust/issues/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

e2ge avatar Apr 19 '18 15:04 e2ge

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?

DeepAQ avatar Feb 09 '19 12:02 DeepAQ

@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

e2ge avatar Feb 09 '19 20:02 e2ge

@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!

DeepAQ avatar Feb 11 '19 06:02 DeepAQ

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

bigtan avatar Aug 07 '19 16:08 bigtan

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

testcaoy7 avatar Aug 30 '19 10:08 testcaoy7

https://github.com/shadowsocks/shadowsocks-rust/issues/163

@testcaoy7

bigtan avatar Aug 31 '19 12:08 bigtan

用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

z16166 avatar Dec 09 '19 17:12 z16166

这个找不到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里

zonyitoo avatar Dec 10 '19 02:12 zonyitoo

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

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

z16166 avatar Dec 10 '19 05:12 z16166

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

zonyitoo avatar Dec 10 '19 06:12 zonyitoo

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

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

z16166 avatar Dec 10 '19 08:12 z16166

我试了一下,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 avatar Dec 29 '19 10:12 e2ge

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

e2ge avatar Dec 29 '19 11:12 e2ge

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

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

zonyitoo avatar Dec 29 '19 11:12 zonyitoo

https://github.com/shadowsocks/shadowsocks-rust/issues/163 直接用这个,编译非常顺畅

bigtan avatar Dec 29 '19 11:12 bigtan

https://github.com/shadowsocks/shadowsocks-rust/blob/master/build/Dockerfile.x86_64-pc-windows-gnu

或者看一下Docker Build的写法。

zonyitoo avatar Dec 29 '19 11:12 zonyitoo

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

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

e2ge avatar Jan 06 '20 02:01 e2ge

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

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

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

zonyitoo avatar Jan 06 '20 17:01 zonyitoo

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

zonyitoo avatar Feb 09 '20 16:02 zonyitoo

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

voltwu avatar May 25 '20 09:05 voltwu

Please @Mygod @madeye check this problem.

zonyitoo avatar May 25 '20 13:05 zonyitoo