简体   繁体   English

无法正确交叉编译 MinGW 中的 C++ 文件

[英]Can't cross compile C++ files in MinGW properly

I'm trying to compile my C++ app for Windows, using my Linux machine.我正在尝试使用我的 Linux 机器为 Windows 编译我的 C++ 应用程序。 My issue occurs when I'm executing the compiled exe.当我执行编译的 exe 时出现我的问题。

Here's a quick example of my issue.这是我的问题的一个快速示例。

helloworld.cpp:你好世界.cpp:

#include <iostream>

int main()
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

This code compiles and runs perfectly using g++ on Linux.此代码在 Linux 上使用 g++ 编译并完美运行。 But when I try compiling it with mingw: i686-w64-mingw32-g++ helloworld.cpp -o helloworld.exe it compiles, but when I try running Windows tells me libgcc_s_dw2-1.ddl is missing .但是当我尝试用 mingw 编译它时: i686-w64-mingw32-g++ helloworld.cpp -o helloworld.exe它编译,但是当我尝试运行 Windows 时告诉我libgcc_s_dw2-1.ddl is missing

I resolved this problem using the -static-libgcc -static-libstdc++ compiler flags to static link all the needed libraries, but Windows still gives me an error: libwinpthread-1.dll is missing .我使用-static-libgcc -static-libstdc++编译器标志静态链接所有需要的库解决了这个问题,但 Windows 仍然给我一个错误: libwinpthread-1.dll is missing

I haven't found anything useful yet, to answer my question, so does anyone know how do I correctly compile this code to Win32 using MinGW-w64?我还没有找到任何有用的东西来回答我的问题,那么有谁知道如何使用 MinGW-w64 将此代码正确编译到 Win32? Thanks!谢谢!

To build a fully static file you should not only use -static-libgcc and/or -static-libstdc++ , but also -static to tell the linker to include static versions of any other libraries.要构建一个完全静态的文件,您不仅应该使用-static-libgcc和/或-static-libstdc++ ,还应该使用-static来告诉链接器包含任何其他库的静态版本。

Or you can just build the shared library, but then you will need to distribute any DLL the EXE depends on it with the EXE and put the DLL in the same path as the EXE (or anywhere in a location listed in the PATH environment variable).或者您可以只构建共享库,但是您需要将 EXE 依赖于它的任何 DLL 与 EXE 一起分发,并将 DLL 放在与 EXE 相同的路径中(或在PATH环境变量中列出的位置中的任何位置) .

I wrote a tool called copypedeps as part of https://github.com/brechtsanders/pedeps to copy just those dependencies.我编写了一个名为copypedeps的工具作为https://github.com/brechtsanders/pedeps 的一部分来复制这些依赖项。

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

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