让 C++ 在 Eclipse 中编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9368976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:45:17  来源:igfitidea点击:

Getting C++ to compile inside Eclipse

c++eclipseeclipse-cdt

提问by IAmYourFaja

Trying to get Eclipse CDT plugin to compile a simple C++ app. I create a new C++ project, and add 1 file (test.cpp) and code it up like a "Hello, world!" example:

试图让 Eclipse CDT 插件编译一个简单的 C++ 应用程序。我创建了一个新的 C++ 项目,并添加了 1 个文件 ( test.cpp) 并将其编码为“你好,世界!” 例子:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, world!";
    return 0;
}

I get highlighted syntax errors on using namespace stdand cout, stating (respectively):

我在using namespace std和上突出显示了语法错误cout,声明(分别):

Symbol 'std' could not be resolved Symbol 'cout' could not be resolved

无法解析符号“std” 无法解析符号“cout”

I'm sure I didn't install CDT with everything it needed to compile/build a full C++ app. Where could I start looking to figure out what I'm missing?

我确定我没有安装 CDT 以及编译/构建完整 C++ 应用程序所需的一切。我可以从哪里开始寻找我缺少的东西?

回答by ondrisko

Do you have a compiler? Quoting eclipse documentation: 'Eclipse IDE for C/C++ Developers does not contain a compiler or debugger; if your system does not have one, you need to download and install one. Please see the Before you beginsection of the C/C++ Development User Guide.'

你有编译器吗?引用eclipse 文档:'Eclipse IDE for C/C++ Developers 不包含编译器或调试器;如果您的系统没有,您需要下载并安装一个。请参阅C/C++ 开发用户指南的开始之前部分。

There you can choose and find out how to install a compiler.

在那里您可以选择并了解如何安装编译器。

Specifically for your unresolved symbols problem, you need to have correct paths set in Project->Properties->C/C++ General->Paths and Symbols/Includes tab, which depends on the compiler you choose to install.

特别是对于未解决的符号问题,您需要在 Project->Properties->C/C++ General->Paths and Symbols/Includes 选项卡中设置正确的路径,这取决于您选择安装的编译器。

回答by Philip Dodson

I don't know what OS you have, but if you are on a Mac, the following worked for me:

我不知道你有什么操作系统,但如果你在 Mac 上,以下对我有用:

  1. Verify Xcode is installed.

  2. Open your Terminalwindow and type:

    xcode-select --install

  1. 验证 Xcode 是否已安装

  2. 打开终端窗口并输入:

    xcode-select --install

Now the "'std' could not be resolved" error should disappear.

现在“'std'无法解决”错误应该消失。

Now, to run your Hello World application:

现在,运行您的 Hello World 应用程序:

  1. Click the Run icon. You are then prompted to select your Run Configuration. The Run Configuration window can also be reached by clicking the drop down arrow from the Run Icon or using the Run menu.

  2. Your configuration should be for a C++ Application. On the "Main" tab, click the "Search Project" button.

  3. In the Binaries box, there should be a binary with the name of your project pre-selected. Click OK.

  4. Click the Run button at the bottom of the "Run Configurations" window.

  1. 单击运行图标。然后会提示您选择您的运行配置。也可以通过单击“运行”图标的下拉箭头或使用“运行”菜单来访问“运行配置”窗口。

  2. 您的配置应该用于 C++ 应用程序。在“主要”选项卡上,单击“搜索项目”按钮

  3. 在 Binaries 框中,应该有一个二进制文件,其中预先选择了您的项目名称。单击确定。

  4. 单击“运行配置”窗口底部的运行按钮。

Hopefully your project then runs, and you see "Hello, world!" in the Console window at the bottom of Eclipse.

希望您的项目随后运行,并且您会看到“Hello,world!” 在 Eclipse 底部的控制台窗口中。

I would also like to add, I still have issues sometimes with std not being found. When I restart my computer, this goes away. Wish I knew why.

我还想补充一点,有时我仍然遇到找不到 std 的问题。当我重新启动计算机时,这会消失。希望我知道为什么。

EDIT: This problem came back and now I can't make it go away!! Anyone know how to fix? I am sure it is something with project/compiler settings.

编辑:这个问题又回来了,现在我无法让它消失!!有谁知道怎么修?我确定它与项目/编译器设置有关。