Skip to content

windows快速编译[静态链接] #163

New issue

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

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

Already on GitHub? # to your account

Closed
bigtan opened this issue Aug 8, 2019 · 19 comments
Closed

windows快速编译[静态链接] #163

bigtan opened this issue Aug 8, 2019 · 19 comments
Labels

Comments

@bigtan
Copy link

bigtan commented Aug 8, 2019

首先,安装vcpkg,然后进行集成

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install

然后,安装libsodium和openssl的windows静态库

vcpkg install openssl:x64-windows-static
vcpkg install libsodium:x64-windows-static

设置rust静态链接

set RUSTFLAGS=-Ctarget-feature=+crt-static

按照shadowsocks-rust的正常安装流程安装

cargo build --release

这样编译出来就是静态链接的单文件版。

@Mignet
Copy link

Mignet commented Nov 13, 2019

补充一点,如果你的vcpkg安装在别的目录,那么
在安装libsodium和openssl的windows静态库前,一定要把vcpkg路径加入到Path环境变量中
然后在shadowsocks-rust目录下执行下面的内容:
vcpkg install openssl:x64-windows-static
vcpkg install libsodium:x64-windows-static
切记

@z16166
Copy link

z16166 commented Dec 10, 2019

cargo编译时,有这个错误信息:

error: couldn't read D:\shadowsocks-rust\target\release\build\libsodium-ffi-ee34e272ed6bc8e7\out/bindings.rs: 系统找不到指定的文件。 (os error 2)
--> C:\Users\happy.cargo\registry\src\github.heygears.com-1ecc6299db9ec823\libsodium-ffi-0.2.2\src\lib.rs:6:1
|
6 | include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile libsodium-ffi.
warning: build failed, waiting for other jobs to finish...
error: build failed

@zonyitoo
Copy link
Collaborator

上面还有更多的错误信息么?这里看起来像是out/bindings.rs没有了。

@z16166
Copy link

z16166 commented Dec 10, 2019

就这个信息。我把Rust的rustup、cargo等都全部卸载了重装,把shadowsocks-rust整个目录删了重新clone下来,也是这个错误。

另外,多服务器的负载均衡的处理流程应该是有点问题的,我这里有21个服务器,其中一部分可能连不上,然后通过shadowsocks-rust访问需要翻墙的网站时,就会有较大概率出现好多秒的卡顿。不过这个和编译无关,可以另搞issue。

@zonyitoo
Copy link
Collaborator

就这个信息。我把Rust的rustup、cargo等都全部卸载了重装,把shadowsocks-rust整个目录删了重新clone下来,也是这个错误。

这个就有点申请,Travis上我也有做一个MSVC版本的CI,日常编译并没有问题。看来我要自己弄一台Windows机来试一下。

@bigtan
Copy link
Author

bigtan commented Dec 10, 2019

@zonyitoo 真实的报错原因应该是vcpkg的libsodium出来的:
Failed to find "libsodium" in vcpkg, falling back to pkg-config

@bigtan
Copy link
Author

bigtan commented Dec 10, 2019

@zonyitoo
···
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
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
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.
···

@zonyitoo
Copy link
Collaborator

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

这一句是因为没有装CLANG,bindgen需要libclang才能跑。

@zonyitoo
Copy link
Collaborator

弄了两天时间终于成功用Docker交叉编译出GNU ABI

https://github.com/shadowsocks/shadowsocks-rust/releases/tag/v1.8.0-alpha.2

@bigtan @z16166 可以考虑直接下载试试。之后就不用再自己编了,直接下载Release的就好。

@z16166
Copy link

z16166 commented Dec 13, 2019

谢谢大佬

试用了一下sslocal.exe,一般没啥问题,chrome偶尔会有走代理访问失败网页的情况(我先打开facebook、twitter、文学城的页面预热了一会儿,然后打开了文学城的3个网页,chrome的窗口正中间都报代理有问题,无法访问,chrome左下的状态栏会一直显示正在等待代理隧道的响应。我把这个叫做卡顿。隔了一会再刷新3个页面就又好了。现象跟我用自己编译的只开了aes-cfb这个feature的sslocal.exe是一样的),此时我看了一下sslocal.exe的日志,只有trust dns的那条“failed to associate send_message response to the sender”。

@zonyitoo
Copy link
Collaborator

可能需要开一下详细的日志,加-vv试一下看看它是卡在哪了

@z16166
Copy link

z16166 commented Dec 15, 2019

详细日志我贴在issue #151的最下面了

#151

@z16166
Copy link

z16166 commented Dec 30, 2019

刚升级了rust toolchain,pull下来最新的代码,用楼主的方法编译通过了。不过vcpkg不需要在PATH中。

info: checking for self-updates
info: downloading self-update

stable-x86_64-pc-windows-gnu updated - rustc 1.40.0 (73528e339 2019-12-16)
stable-x86_64-pc-windows-msvc updated - rustc 1.40.0 (73528e339 2019-12-16)

D:\shadowsocks-rust>rustup default stable-x86_64-pc-windows-msvc
info: using existing install for 'stable-x86_64-pc-windows-msvc'
info: default toolchain set to 'stable-x86_64-pc-windows-msvc'

stable-x86_64-pc-windows-msvc unchanged - rustc 1.40.0 (73528e339 2019-12-16)

D:\shadowsocks-rust>set RUSTFLAGS=-Ctarget-feature=+crt-static

D:\shadowsocks-rust>cargo build --release
...(此处省略3千字)
Compiling serde_urlencoded v0.6.1
Compiling shadowsocks-rust v1.8.0 (D:\shadowsocks-rust)
Finished release [optimized] target(s) in 5m 49s

@zonyitoo
Copy link
Collaborator

不用vcpkg的话,应该是libsodium用自带的静态库来连接。

@z16166
Copy link

z16166 commented Dec 30, 2019

是在另外一个DOS窗口中执行的如下命令,跟执行cargo的不是同一个DOS窗口。执行cargo的这个DOS窗口的PATH中没有vcpkg.exe,也不需要在Shadowsocks-Rust的目录下执行下面的命令。我看楼主后来补充的帖子强调了这一点。

vcpkg install openssl:x64-windows-static
vcpkg install libsodium:x64-windows-static

@arloor
Copy link

arloor commented Mar 23, 2020

2020.3.23 使用 stable-x86_64-pc-windows-msvc (default) rustc 1.42.0 (b8cedc004 2020-03-09) 工具链

仍然提示找不到openssl库,于是手动设置openssl库的地址,下面是我的步骤。

首先,安装vcpkg,然后进行集成

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install

然后,安装libsodium和openssl的windows静态库

vcpkg install openssl:x64-windows-static
vcpkg install libsodium:x64-windows-static

设置rust静态链接

set RUSTFLAGS=-Ctarget-feature=+crt-static
set OPENSSL_LIB_DIR="C:\\Users\arloor\\CLionProjects\\socks5-https\\vcpkg\\installed\\x64-windows-static\\lib"

按照shadowsocks-rust的正常安装流程安装

cargo build --release

这样编译出来就是静态链接的单文件版。

@janus-xiao
Copy link

弄了两天时间终于成功用Docker交叉编译出GNU ABI

https://github.com/shadowsocks/shadowsocks-rust/releases/tag/v1.8.0-alpha.2

@bigtan @z16166 可以考虑直接下载试试。之后就不用再自己编了,直接下载Release的就好。

请问下载之后怎么用

@LuoZijun
Copy link
Contributor

@zonyitoo 现在这个应该可以解决了?

@zonyitoo
Copy link
Collaborator

Yup.

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

No branches or pull requests

7 participants