【问题标题】:How to compile and run C++ with MinGW using Eclipse and CDT?如何使用 Eclipse 和 CDT 使用 MinGW 编译和运行 C++?
【发布时间】:2010-10-20 14:26:12
【问题描述】:

我想在 Windows 上使用 Eclipse 和 CDT 插件进行一些 C++ 开发。我使用 Eclipse Helios SR1 并安装了 CDT 插件。我还安装了MinGW,现在我在 Eclipse 中编写了一个简单的“Hello World”。

你好.cpp

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World" << endl;
    return 0;
}

在 Eclipse 中使用 CDT 插件和 MinGW 编译器。如何编译我的程序?以及如何在 Eclipse 中测试运行程序?

【问题讨论】:

    标签: c++ eclipse configuration mingw eclipse-cdt


    【解决方案1】:

    【讨论】:

    • 谢谢,我没有设置 MinGW 和 MSYS 的环境变量。
    【解决方案2】:

    在浏览了许多主题和文章后,我找到了解决方案。 使用 C/C++ 开发工具 9.2.1.201704050430 和 MinGW 在 Eclipse Neon.3 Release (4.6.3) 上在 Windows 10 x64 上测试的解决方案

    系统配置

    1. 下载 MinGW。任何发行版都可能有效。我使用了http://isocpp.org/ 上推荐的distro
    2. 解压存档到C:\MinGW(实际上是C:\,因为存档包含文件夹MinGW
    3. RMB on This PC -> Properties -> Additional system settings -> 标签Advanced-> 按钮Environment variables
    4. 在第二个表System variables 上单击New。命名变量MINGW_HOME 并将路径设置为MinGW 安装文件夹C:\MinGW 然后OK
    5. 在表中找到变量Path并选择Edit
    6. 在新窗口中点击New并输入%MINGW_HOME%\bin\
    7. 在打开的窗口中单击OK 确认操作
    8. 您可以通过在命令行中输入g++ --version 来检查新工具的可用性,您应该会看到类似

    g++ (GCC) 6.3.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Eclipse CDT 配置

    1. 安装 Eclipse with CDT 或将 CDT 添加到现有的 Eclipse 安装中
    2. 转到安装了 MinGW (C:\MinGW\bin\) 的文件夹。复制文件gcc.exe(请勿重命名原始文件!)
    3. 将复制的文件重命名为mingw32-gcc.exe\MinGW\bin\ 中应该有两个文件gcc.exemingw32-gcc.exe
    4. 打开 Eclipse 并选择 C\C++ 透视图
    5. 转到Window -> Preferences -> C\C++ -> Build -> Environment
    6. 单击Add 并键入PATH 作为名称,然后单击Variables 并选择Path。通过Ok 确认。
    7. 点击Select,然后点击Ok,选择新变量PATH
    8. 重启 Eclipse

    现在你应该可以编译 Hello World 程序了。只需选择New -> C++ Project。在这里你应该看到可用的 MinGW 作为工具链

    【讨论】:

      【解决方案3】:

      这是在 Eclipse 上安装 MinGW 的另一个好资源:http://chrismwright.wordpress.com/2012/10/13/installing-eclipse-for-cc-and-mingw/

      几乎是一步一步的安装,最后包括 Hello World 示例......

      【讨论】:

      【解决方案4】:

      只需将MinGW 添加到系统路径(AndriiL 帖子中的系统配置部分)就足够了。以${PATH} 为值的名为PATH 的变量将自动添加到Window -&gt; Preferences -&gt; C\C++ -&gt; Build -&gt; Environment 中,您可以在项目向导中看到MinGW GCC 作为工具链选项。如果没有提供PATH变量,Eclipse CDT可能不会加载OS中最近的系统路径更改(点击Select...并选择Path variable,该值可能不包含MinGW路径),只需退出Eclipse并再次打开它。

      【讨论】:

        【解决方案5】:

        Chocolatey 是一个包管理器,它允许使用 Windows Powershell 通过单个命令进行 mingw 安装。

        choco install mingw --version=8.1.0
        

        安装完成后,将以下工具链路径添加到Eclipse->Window->Preferences->Core Build ToolChains -> User Defined ToolChains。

        C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\gcc.exe
        

        重启eclipse。 MinGW 工具链现在应该可以在 Eclipse 中使用了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-07-07
          • 2015-03-23
          • 1970-01-01
          • 1970-01-01
          • 2015-11-19
          • 1970-01-01
          • 2013-11-19
          • 1970-01-01
          相关资源
          最近更新 更多