简体   繁体   English

Mingw32 无法静态链接到 libgcc_s_dw2-1、libstdc++-6、libwinpthread-1 (Qt 5.7.1)

[英]Mingw32 failing to statically link to libgcc_s_dw2-1, libstdc++-6, libwinpthread-1 (Qt 5.7.1)

I am struggling with a problem of statically linking with libgcc_s_dw2-1, libstdc++-6, libwinpthread-1 libraries when compiling with mingw32.在使用 mingw32 编译时,我正在努力解决与 libgcc_s_dw2-1、libstdc++-6、libwinpthread-1 库进行静态链接的问题。 Setting up a project with -static-libgcc -static-libstdc++ -static -lwinpthread flags helps in case if I build a standalone application.如果我构建一个独立的应用程序,使用-static-libgcc -static-libstdc++ -static -lwinpthread标志设置一个项目会有所帮助。 But when I use Qt 5.7.1 for mingw32 compiler, it does not help.但是当我将 Qt 5.7.1 用于 mingw32 编译器时,它没有帮助。 The application won't start complaining that these libs are missing!应用程序不会开始抱怨缺少这些库!

Here is my CMakeLists.txt这是我的 CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(dummyapp LANGUAGES CXX)

find_package(Qt5 REQUIRED COMPONENTS Core)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static -lwinpthread")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

add_executable(app
        app.cpp)

target_link_libraries(app
        PRIVATE
            Qt5::Core
        )

add_custom_command(TARGET app PRE_LINK
        COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:app>
        )

app.cpp应用程序.cpp

#include <iostream>
#include <QVariant>

int main(int argc, const char **argv)
{
    std::cout << "Hello dummy!" << std::endl;

    QVariant var{};

    std::cin.get();

    return 0;
}

I suspect, that the reason for this behavior is that Qt itself was built linking to those libs dynamically.我怀疑,这种行为的原因是 Qt 本身是动态链接到这些库的。

What is the solution?解决办法是什么? Is there a remedy?有补救措施吗? If not, how can I deploy those libs automatically on build?如果没有,我如何在构建时自动部署这些库?

If your build and it's dependancies aren't static, those DLLs need to be distributed with your application.如果您的构建及其依赖项不是 static,则这些 DLL 需要与您的应用程序一起分发。 The article at https://lwn.net/Articles/549573/ explains the libstdc++-6 DLL can be distributed without licensing issues. https://lwn.net/Articles/549573/上的文章解释了 libstdc++-6 DLL 可以在没有许可问题的情况下分发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM