shadowsocks-qt5
shadowsocks-qt5 copied to clipboard
在msys2下编译
1,需要编译botan,按照libQtShadowsocks提供的编译指导里提供的参数--prefix=/mingw64 --disable-modules=tls --os=mingw --without-stack-protector进行编译然后安装
2,编译libQtShadowsocks
mkdir build && cd build
cmake -G "MinGW Makefiles" .. -DUSE_BOTAN2=ON -DCMAKE_INSTALL_PREFIX=/mingw64
mingw32-make -j4
mingw32-make install
3,~~编译libqrencode~~安装mingw-w64-x86_64-qrencode即可,cmake提示找不到依赖直接安装源里的mingw包即可 4,编译shadowsocks-qt5 需要修改 src/CMakeLists.txt和CMakeLists.txt,添加libiconv,~~msys2中有可用的libiconv,不过需要自己添加iconv.pc到/mingw64/lib/pkgconfig~~mingw已经打包了.pc文件Alexpux/MINGW-packages issue3858
target_link_libraries(${APP_NAME}
PUBLIC Qt5::Core
PUBLIC Qt5::Gui
PUBLIC Qt5::Widgets
PUBLIC Qt5::Network
PRIVATE ${QSS_LIBRARY_VAR}
PRIVATE ${QRENCODE_LIBRARY_VAR}
PRIVATE ${ZBAR_LIBRARY_VAR}
PRIVATE ${ICONV_LIBRARY_VAR})
target_include_directories(${APP_NAME}
PRIVATE ${QSS_INCLUDE_DIRS}
PRIVATE ${QRENCODE_INCLUDE_DIRS}
PRIVATE ${ZBAR_INCLUDE_DIRS}
PRIVATE ${ICONV_INCLUDE_DIRS})
pkg_check_modules(ICONV REQUIRED iconv)
find_library(ICONV_LIBRARY_VAR
NAMES libiconv.a
HINTS ${ICONV_LIBRARY_DIRS} ${ICONV_LIBDIR})
然后进行编译
mkdir build && cd build
cmake -G "MinGW Makefiles" ..
mingw32-make -j4
成功后可以在 build/src 下看到编译好的ss-qt5.exe,但是为了能够运行还需要从/mingw64下复制一些dll到exe所在目录,下面是dll列表
libbz2-1.dll
libgcc_s_seh-1.dll
libgraphite2.dll
libiconv-2.dll
libicuin61.dll
libintl-8.dll
libpcre2-16-0.dll
libQtShadowsocks.dll
libwinpthread-1.dll
Qt5Gui.dll
Qt5Widgets.dll
libfreetype-6.dll
libglib-2.0-0.dll
libharfbuzz-0.dll
libicudt61.dll
libicuuc61.dll
libpcre-1.dll
libpng16-16.dll
libstdc++-6.dll
Qt5Core.dll
Qt5Network.dll
zlib1.dll
其中libQtShadowsocks.dll不在系统目录,之前编译的时候没有安装到系统,在 build/lib 上面步骤中cmake需要把系统里的/bin/sh.exe暂时改成其他文件名才能继续
折腾了两个上午编译出了可用的包,以上步骤可能有遗漏,供参考
20180527补充:使用mingw编译要安装mingw的make,pkg-config等工具链
后来用Enigma Virtual Box封装了一下,一个可执行程序28.6M,大小还可以接受
@amazingfate 可以分享下编译成功心得吗?
Google一圈你就會發現CMake, Qt, Windows, Static linking加在一起是一個無解的難題,這就是為什麼我不提供Windows預編譯可執行碼的原因。另一方面,使用dynamic linking就會有一個20+MB的zip包 :(
@librehat 以前提供的预编译包是静态编译的吗,静态编译的话用mxe应该还好,msys2我以前折腾过静态编译坑挺多的
以前一直都是提供的靜態鏈接的可執行碼,用qmake的時候比較好hack link line,現在cmake比較難搞
以前看过一个项目是在linux上用mxe静态编译qt程序,一整套都用的cmake:baka-mplayer cross compile
静态编译了libQtShadowsocks.a, 尝试-DCMAKE_EXE_LINKER_FLAGS="-static"参数编译结果报了一堆错
[100%] Linking CXX executable ss-qt5.exe
CMakeFiles\ss-qt5.dir/objects.a(mainwindow.cpp.obj):mainwindow.cpp:(.text+0x3d85): undefined reference to `__imp__ZN3QSS6Common7versionEv'
CMakeFiles\ss-qt5.dir/objects.a(ssvalidator.cpp.obj):ssvalidator.cpp:(.text+0x1c): undefined reference to `__imp__ZN3QSS6Cipher16supportedMethodsB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(ssvalidator.cpp.obj):ssvalidator.cpp:(.text+0x198): undefined reference to `__imp__ZN3QSS7Profile7fromUriERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(ssvalidator.cpp.obj):ssvalidator.cpp:(.text+0x1a8): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x24e): undefined reference to `__imp__ZNK3QSS7Profile11toUriSip002B5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x25e): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x2b0): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x539): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x549): undefined reference to `__imp__ZN3QSS10Controller19runningStateChangedEb'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x5ae): undefined reference to `__imp__ZN3QSS10Controller19tcpLatencyAvailableEi'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x63f): undefined reference to `__imp__ZN3QSS10Controller16newBytesReceivedEy'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x6ca): undefined reference to `__imp__ZN3QSS10Controller12newBytesSentEy'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x756): undefined reference to `__imp__ZN3QSS10Controller5startEv'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x77e): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x838): undefined reference to `__imp__ZN3QSS13AddressTesterC1ERK12QHostAddressRKtP7QObject'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x855): undefined reference to `__imp__ZN3QSS13AddressTester24connectivityTestFinishedEb'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x8ca): undefined reference to `__imp__ZN3QSS13AddressTester15lagTestFinishedEi'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x94a): undefined reference to `__imp__ZNK3QSS7Profile8passwordB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x95d): undefined reference to `__imp__ZNK3QSS7Profile6methodB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x97c): undefined reference to `__imp__ZN3QSS13AddressTester21startConnectivityTestERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_i'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x98c): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0x9bc): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0xb67): undefined reference to `__imp__ZN3QSS13AddressTester15lagTestFinishedEi'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text+0xd23): undefined reference to `__imp__ZN3QSS10Controller16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_[_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_]+0x3c): undefined reference to `__imp__ZN3QSS7ProfileC1EOS0_'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_[_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_]+0x93): undefined reference to `__imp__ZN3QSS10ControllerC1ENS_7ProfileEbbP7QObject'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_[_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_]+0xb2): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_[_ZSt11make_uniqueIN3QSS10ControllerEJNS0_7ProfileEbbEENSt9_MakeUniqIT_E15__single_objectEDpOT0_]+0xdf): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZN7QObject7connectIMN3QSS10ControllerEFviEM10ConnectionFviEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE[_ZN7QObject7connectIMN3QSS10ControllerEFviEM10ConnectionFviEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE]+0x9e): undefined reference to `__imp__ZN3QSS10Controller16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZN7QObject7connectIMN3QSS10ControllerEFvyEM10ConnectionFvRKyEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESE_PKNSD_IT0_E6ObjectESJ_N2Qt14ConnectionTypeE[_ZN7QObject7connectIMN3QSS10ControllerEFvyEM10ConnectionFvRKyEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESE_PKNSD_IT0_E6ObjectESJ_N2Qt14ConnectionTypeE]+0x9e): undefined reference to `__imp__ZN3QSS10Controller16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZN7QObject7connectIMN3QSS13AddressTesterEFvbEM10ConnectionFvbEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE[_ZN7QObject7connectIMN3QSS13AddressTesterEFvbEM10ConnectionFvbEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE]+0x9e): undefined reference to `__imp__ZN3QSS13AddressTester16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZN7QObject7connectIMN3QSS13AddressTesterEFviEM10ConnectionFviEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE[_ZN7QObject7connectIMN3QSS13AddressTesterEFviEM10ConnectionFviEEEN11QMetaObject10ConnectionEPKN9QtPrivate15FunctionPointerIT_E6ObjectESC_PKNSB_IT0_E6ObjectESH_N2Qt14ConnectionTypeE]+0x9e): undefined reference to `__imp__ZN3QSS13AddressTester16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_Z12qobject_castIPN3QSS13AddressTesterEET_P7QObject[_Z12qobject_castIPN3QSS13AddressTesterEET_P7QObject]+0xf): undefined reference to `__imp__ZN3QSS13AddressTester16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(connection.cpp.obj):connection.cpp:(.text$_ZN7QObject10disconnectIMN3QSS13AddressTesterEFviEM10ConnectionFviEEEbPKN9QtPrivate15FunctionPointerIT_E6ObjectESA_PKNS9_IT0_E6ObjectESF_[_ZN7QObject10disconnectIMN3QSS13AddressTesterEFviEM10ConnectionFviEEEbPKN9QtPrivate15FunctionPointerIT_E6ObjectESA_PKNS9_IT0_E6ObjectESF_]+0x49): undefined reference to `__imp__ZN3QSS13AddressTester16staticMetaObjectE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x281): undefined reference to `__imp__ZNK3QSS7Profile4nameB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x2c0): undefined reference to `__imp__ZNK3QSS7Profile12localAddressB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x2ff): undefined reference to `__imp__ZNK3QSS7Profile9localPortEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x319): undefined reference to `__imp__ZNK3QSS7Profile10serverPortEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x333): undefined reference to `__imp__ZNK3QSS7Profile13serverAddressB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x372): undefined reference to `__imp__ZNK3QSS7Profile6methodB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x3cd): undefined reference to `__imp__ZNK3QSS7Profile8passwordB5cxx11Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x40c): undefined reference to `__imp__ZNK3QSS7Profile7timeoutEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x425): undefined reference to `__imp__ZNK3QSS7Profile9httpProxyEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x43e): undefined reference to `__imp__ZNK3QSS7Profile5debugEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x54e): undefined reference to `__imp__ZN3QSS7Profile7fromUriERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x58b): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x5b1): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x67c): undefined reference to `__imp__ZN3QSS7ProfileC1Ev'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x6a4): undefined reference to `__imp__ZN3QSS7Profile7setNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x6d8): undefined reference to `__imp__ZN3QSS7Profile16setServerAddressERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x6fe): undefined reference to `__imp__ZN3QSS7Profile13setServerPortEt'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x726): undefined reference to `__imp__ZN3QSS7Profile15setLocalAddressERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x74c): undefined reference to `__imp__ZN3QSS7Profile12setLocalPortEt'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x782): undefined reference to `__imp__ZN3QSS7Profile9setMethodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x7c1): undefined reference to `__imp__ZN3QSS7Profile11setPasswordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x7e3): undefined reference to `__imp__ZN3QSS7Profile10setTimeoutEi'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x7fd): undefined reference to `__imp__ZN3QSS7Profile12setHttpProxyEb'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x816): undefined reference to `__imp__ZN3QSS7Profile11enableDebugEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x828): undefined reference to `__imp__ZN3QSS7Profile12disableDebugEv'
CMakeFiles\ss-qt5.dir/objects.a(sqprofile.cpp.obj):sqprofile.cpp:(.text+0x8a2): undefined reference to `__imp__ZN3QSS7ProfileD1Ev'
@librehat 其实dynamic linking还能接受吧,用Enigma Virtual Box可以把dll都封装到一个exe里,不到30M大小和以前的静态编译没什么大的差别
这是编译好的exe文件 https://pan.baidu.com/s/1otD8C6bgOBl_6TidI9RzhA
cmake 报错 botan-2已经安装了, 求助
$ ls /mingw64/lib/libbotan-2.a -l -rw-r--r-- 1 kingsoft None 10998086 7月 28 08:56 /mingw64/lib/libbotan-2.a
=================================== window10 x64 cmake 错误信息
-- Found PkgConfig: C:/msys64/mingw64/lib/pkgconfig (found version "") -- Checking for one of the modules 'botan-2>=2.3.0;botan-1.10' CMake Error at C:/msys64/mingw64/share/cmake-3.12/Modules/FindPkgConfig.cmake:664 (message): None of the required 'botan-2>=2.3.0;botan-1.10' found Call Stack (most recent call first): CMakeLists.txt:23 (pkg_search_module)
CMake Deprecation Warning at CMakeLists.txt:28 (message): Botan-1.10 is found and will be used in this build. However, Botan-1.10 is deprecated and should not be used if possible
CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: BOTAN_LIBRARY_VAR linked by target "QtShadowsocks" in directory C:/msys64/home/kingsoft/libQtShadowsocks/lib
-- Configuring incomplete, errors occurred! See also "C:/msys64/home/kingsoft/libQtShadowsocks/build/CMakeFiles/CMakeOutput.log".
需要安装 mingw-w64-x86_64-pkg-config
在 Linux 静态编译 clang-format 遇到过类似的问题,需要 CMAKE_FIND_LIBRARY_SUFFIXES 和 CMAKE_EXE_LINKER_FLAGS 配合。上面的问题可能是因为 QT 库仍然是动态的,不参与链接。我没有Windows开发环境,改天搭一个试试。
https://blog.kitware.com/creating-static-executables-on-linux
cmake \
-DITK_DIR=/path/to/static/ITK \
-DCMAKE_EXE_LINKER_FLAGS="-static" \
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
~/src/BuildAHelloWorldProgram
搭了个环境尝试编译 ss-qt5。发现只要将 libQtShadowsocks 编译为静态库,就一定会报 @amazingfate 的问题。那些未定义的符号是 libQtShadowsocks 的内容。结果很奇怪。
成功编译了 32 位版本,采用 Enigma Virtual Box 包了一下,但多出两个 libicu 的依赖库,可执行文件剧增到 68M。