静态编译 X64 的 OpenVPN
说明
- 因为链接 libdl.a 和 libpthread.a 会出问题,所以这些系统一般会自带的库选择动态链接
准备工作
编译
#首先从官网下载合适的版本并解压
openvpn_version=2.4.8
wget -O- "https://swupdate.openvpn.org/community/releases/openvpn-$openvpn_version.tar.gz" | tar xz
#进入编译目录
cd openvpn-$openvpn_version
#设置依赖库路径
LIB_OPENSSL=~/x64/lib
LIB_LZO=~/x64/lib
LIB_LZ4=~/x64/lib
#设置依赖头文件路径
INCLUDE_OPENSSL=~/x64/include
INCLUDE_LZO=~/x64/include
INCLUDE_LZ4=~/x64/include
#静态编译
./configure --enable-static --disable-shared --disable-plugins --disable-debug \
OPENSSL_LIBS="-L$LIB_OPENSSL -lssl -lcrypto" \
OPENSSL_CFLAGS="-I$INCLUDE_OPENSSL" \
LZO_LIBS="-L$LIB_LZO -llzo2" \
LZO_CFLAGS="-I$INCLUDE_LZO" \
LZ4_LIBS="-L$LIB_LZ4 -llz4" \
LZ4_CFLAGS="-I$INCLUDE_LZ4"
make LIBS='-all-static' -j $(grep "cpu cores" /proc/cpuinfo | wc -l)
mv src/openvpn/openvpn ..
返回上级目录,去掉执行文件的符号信息和调试信息,减小体积
cd ..
strip openvpn
然后就可以删除源文件了
rm -rf "openvpn-$openvpn_version"