与外部库交叉编译基于Qt的应用程序

时间:2018-12-16 18:23:38

标签: c++ qt cross-compiling mxe

我有一个用C ++编写的基于Qt的应用程序,并且我正在使用fuzzylite 6.0库,我想将其静态链接。

编译和执行在我的Arch Linux机器上可以正常工作。但是,我也想为Windows构建。因此,我使用MXE(MXE_TARGETS=x86_64-w64-mingw32.static)为Windows构建了MXE工具链和Fuzzylite。

除了来自外部库的一些警告(我相信它们使用一些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:

    我在阅读this answer后修改了build.sh以使用cmake的MXE版本,因为它会自动为Windows使用适当的工具链文件。

    $ 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
    

    fuzzylite也有一个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, ...) {
                        ^

0 个答案:

没有答案