我有一个用 C++ 编写的基于 Qt 的应用程序,并且我正在使用fuzzylite 6.0库,我想静态链接它。
编译和执行在我的 Arch Linux 机器上完美运行。但是,我也想为 Windows 构建。因此,我使用 MXE ( )为 Windows 构建了MXE工具链和 blurlite 。MXE_TARGETS=x86_64-w64-mingw32.static
编译过程运行良好,除了来自外部库的一些警告(我相信他们使用一些 MSVC#pragma
来禁用它们,但它们仍然出现在 MinGW 中)。
但是,生成的 PE 可执行文件在 x86_64 Windows 机器上完全没有任何作用。当我启动可执行文件时,没有错误,也没有弹出任何内容。
当我在没有fuzzylite(并且没有fuzzylite 相关代码)的情况下编译时,它确实有效,这让我认为在构建我的应用程序或fuzzylite 期间存在问题,但我无法找到解决方案。
以下是我采取的具体步骤:
安装 MXE Qt 工具链:
$ git clone https://github.com/mxe/mxe.git /usr/local/src/mxe $ cd /usr/local/src/mxe/ $ make MXE_TARGETS=x86_64-w64-mingw32.static PREFIX=/usr/local qtbase
构建fuzzylite:
阅读此答案后,我修改
build.sh
为使用 MXE 版本,因为它会自动为 Windows 使用适当的工具链文件。cmake
$ git clone https://github.com/fuzzylite/fuzzylite.git /usr/local/src/fuzzylite $ cd /usr/local/src/fuzzylite/fuzzylite $ sed -i 's/cmake\b/\/usr\/local\/bin\/x86_64-w64-mingw32.static-cmake/g' build.sh $ /usr/local/src/fuzzylite/fuzzylite/build.sh all
blurlite 也有一个
build.bat
文件,但我相信它只能在Windows 环境中执行。安装fuzzylite:
$ cp /usr/local/src/fuzzylite/fuzzylite/release/bin/lib* /usr/local/lib/release/ $ cp /usr/local/src/fuzzylite/fuzzylite/debug/bin/lib* /usr/local/lib/debug/
构建应用程序:
$ x86_64-w64-mingw32.static-qmake-qt5 $ make
这是我的.pro
文件(项目名为code
):
#-------------------------------------------------
#
# Project created by QtCreator 2018-11-19T08:47:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = code
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp \
analyzer.cpp \
overlay.cpp \
ridgeendingengine.cpp \
minutiaengine.cpp \
reversetrapezoid.cpp
HEADERS += \
mainwindow.hpp \
analyzer.hpp \
overlay.hpp \
ridgeendingengine.hpp \
minutiaengine.hpp \
reversetrapezoid.hpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L/usr/local/lib/release/ -lfuzzylite-static
else:win32:CONFIG(debug, debug|release): LIBS += -L/usr/local/lib/debug/ -lfuzzylite-static
else:unix: LIBS += -L/usr/local/lib/ -lfuzzylite-static
INCLUDEPATH += /usr/local/include
DEPENDPATH += /usr/local/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += /usr/local/lib/release/libfuzzylite-static.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += /usr/local/lib/debug/libfuzzylite-static.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += /usr/local/lib/release/fuzzylite-static.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += /usr/local/lib/debug/fuzzylite-static.lib
else:unix: PRE_TARGETDEPS += /usr/local/lib/libfuzzylite-static.a
在构建fuzzylite 和我的应用程序期间生成的警告示例:
In file included from /usr/local/src/fuzzylite/fuzzylite/./fl/Headers.h:33:0,
from /usr/local/src/fuzzylite/fuzzylite/src/main.cpp:17:
/usr/local/src/fuzzylite/fuzzylite/./fl/Exception.h:45:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (push)
^
/usr/local/src/fuzzylite/fuzzylite/./fl/Exception.h:46:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable:4275)
^
/usr/local/src/fuzzylite/fuzzylite/./fl/Exception.h:51:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (pop)
^
In file included from /usr/local/src/fuzzylite/fuzzylite/./fl/term/Term.h:22:0,
from /usr/local/src/fuzzylite/fuzzylite/./fl/factory/ConstructionFactory.h:119,
from /usr/local/src/fuzzylite/fuzzylite/./fl/factory/ActivationFactory.h:22,
from /usr/local/src/fuzzylite/fuzzylite/./fl/Headers.h:55,
from /usr/local/src/fuzzylite/fuzzylite/src/main.cpp:17:
/usr/local/src/fuzzylite/fuzzylite/./fl/Operation.h:993:24: warning: inline function 'static std::__cxx11::string fl::Operation::str(T, int, std::ios_base::fmtflags) [with T = const std::__cxx11::basic_string<char>&; std::__cxx11::string = std::__cxx11::basic_string<char>; std::ios_base::fmtflags = std::_Ios_Fmtflags]' declared as dllimport: attribute ignored [-Wattributes]
inline std::string Operation::str(const std::string& x, int decimals,
^
/usr/local/src/fuzzylite/fuzzylite/./fl/Operation.h:1012:24: warning: inline function 'static std::__cxx11::string fl::Operation::join(const std::vector<T>&, const string&) [with T = std::__cxx11::basic_string<char>; std::__cxx11::string = std::__cxx11::basic_string<char>]' declared as dllimport: attribute ignored [-Wattributes]
inline std::string Operation::join(const std::vector<std::string>& x,
^
/usr/local/src/fuzzylite/fuzzylite/./fl/Operation.h:1038:24: warning: inline function 'static std::__cxx11::string fl::Operation::join(int, const string&, T, ...) [with T = float; std::__cxx11::string = std::__cxx11::basic_string<char>]' declared as dllimport: attribute ignored [-Wattributes]
inline std::string Operation::join(int items, const std::string& separator,
^
/usr/local/src/fuzzylite/fuzzylite/./fl/Operation.h:1054:24: warning: inline function 'static std::__cxx11::string fl::Operation::join(int, const string&, T, ...) [with T = const char*; std::__cxx11::string = std::__cxx11::basic_string<char>]' declared as dllimport: attribute ignored [-Wattributes]
inline std::string Operation::join(int items, const std::string& separator, const char* first, ...) {
^