MinGW .exe需要几个gcc dll,不管代码? [英] MinGW .exe requires a few gcc dll's regardless of the code?

查看:1008
本文介绍了MinGW .exe需要几个gcc dll,不管代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MinGW编译时,我必须在运行exe之前从MinGW bin目录复制某些dll文件(即使使用-static和/或-static-libstdc ++)。
我改变了吗?是否有一个特殊的MinGW构建,我必须使用?最终我想能够运行程序,只有exe在目录中(没有Windows环境变量设置。)这些文件是:





  • libgcc_s_seh-1.dll

  • libwinpthread-1.dll

  • ul>

    这里是步骤完整列表:


    1. 打开代码: :

    2. 选择文件 - > New->项目 - >控制台

    3. 填写项目Hello World li>
    4. 右键单击Project-> Build Options ...-> Hello World(Root target) - > Other Options

    5. 输入-static

    6. CTRL-F9:Build Project(未执行)

    7. 导航到,

    8. 当一个消息弹出说Error:libstdc ++ - 6.dll从您的计算机丢失时,单击确定。

    9. 将/ minGW / bin /目录中的libstdc ++ - 6.dll复制到Hello World.exe目录中。

    10. 运行Hello World.exe

    11. 单击确定出现错误:libgcc_s_seh-1.dll从您的计算机丢失。

    12. 将libgcc_s_seh-1.dll复制到Hello World.exe目录中。

    13. 重复并最终复制libwinpthread-1.dll。
    14. 查看消息

        Hello World! 


    编辑
    我的命令行是:

      g ++。exe -Wall -fexceptions -static -static-libgcc -static-libstdc ++ -g -static-libgcc -static-libstdc ++ -L。 -cC:\Users\ ______ \Desktop\Hello World\main.cpp-o obj\Debug\main.o 
    g ++。exe -obin\Debug\\ \\Hello World.exeobj \Debug\main.o

    以上。为了安全起见,代码是:

      // main.cpp 
    #include< iostream>

    using namespace std;

    int main()
    {
    cout< 你好,世界! << endl;
    return 0;
    }


    解决方案

    错误!



    转到 main.cpp 文件所在的目录,然后尝试以下操作。

      g ++。exe -Wall -c -g main.cpp -o obj\\ \\Debug\main.o 
    g ++。exe -static -static-libgcc -static-libstdc ++ -obin\Debug\Hello World.exeobj\Debug\main.o

    那么你将不再需要复制DLL(对于Hello World程序)。



    其他备注:



    MinGW安装说明建议设置

      c:\minGW; c:\MinGW\bin; 

    到PATH环境变量。



    通常

      -static -static-libgcc -static-libstdc ++ 

    链接器选项应该工作(一次尝试所有3个)。但不适用于 libwinpthread-1.dll



    另外,尝试 code>,然后重新编译。



    没有-static-something命令。



    和libstdc ++ 可以设置为静态链接。



    对于其他库,与-static,然后列出要包含单独的命令,即-lpthread的库。


    When compiling with MinGW, I have to copy over certain dll files from the MinGW bin directory before the exe will run (Even when using "-static" and/or "-static-libstdc++".) How do I change that? Is there a special build of MinGW that I have to use? Ultimately I want to be able to run the program with nothing but the exe in the directory (and no windows environment variables set.) These File's are:

    • libstdc++-6.dll
    • libgcc_s_seh-1.dll
    • libwinpthread-1.dll

    And here is the complete list of step's I fallow:

    1. Open Up Code::Blocks
    2. Select "File->New->Project->Console"
    3. Fill out the project settings for project "Hello World"
    4. Right click Project->Build Options...->Hello World (Root target)->Other Options
    5. Enter "-static" (or "-static-libstdc++") under the already set "-fexceptions"
    6. CTRL-F9 : Build Project (Without executing)
    7. Navigate to, in Windows Explorer, and run the built "Hello World.exe" file.
    8. Click "OK" when a message pop's up saying "Error: libstdc++-6.dll is missing from your computer."
    9. Copy "libstdc++-6.dll" from the /MinGW/bin/ directory, into the "Hello World.exe" directory.
    10. Run "Hello World.exe"
    11. Click "OK" for the message saying "Error: libgcc_s_seh-1.dll is missing from your computer."
    12. Copy "libgcc_s_seh-1.dll" into the "Hello World.exe" directory.
    13. Repeat and end up copying "libwinpthread-1.dll" over aswell.
    14. View the message

      Hello World!
      

    Edit: My command line is:

    g++.exe -Wall -fexceptions -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++ -L. -c "C:\Users\______\Desktop\Hello World\main.cpp" -o obj\Debug\main.o
    g++.exe -o "bin\Debug\Hello World.exe" obj\Debug\main.o
    

    With all the dll files mentioned above required. And, just to be safe, the code is:

    // main.cpp
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "Hello world!" << endl;
        return 0;
    }
    

    解决方案

    Your commands are wrong !

    Go to the directory where your main.cpp file is, and try the following.

    g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
    g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o
    

    then you'll no longer need to copy the DLLs (for your Hello World program).

    Other notes:

    The MinGW installation instructions recommends setting

    c:\minGW;c:\MinGW\bin;
    

    to the PATH environment variable.

    Normally the

    -static -static-libgcc -static-libstdc++
    

    linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll.

    Also, try to clean before recompiling.

    There's no "-static-something" command.

    Only standard libraries libgcc and libstdc++ can be set to static linking.

    For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".

    这篇关于MinGW .exe需要几个gcc dll,不管代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆