Eclipse C/C++ 显示错误但编译? [英] Eclipse C/C++ Shows Errors but Compiles?

查看:30
本文介绍了Eclipse C/C++ 显示错误但编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在 Eclipse 中构建一些 Arduino 代码,如你的第二个 Arduino 项目,但每次我使用 Arduino 库时,例如 Serial,Eclipse 都会在我的函数名称下划线,声称它们无法解析.但是,代码实际上可以编译,所以我有点不明白为什么 Eclipse 认为这些函数丢失了.如果有人对如何解决这个问题有任何想法,我们将不胜感激.先谢谢了.

So I am building some Arduino code in eclipse, as described in Your Second Arduino Project, but every time I use an Arduino library, such as Serial, Eclipse underlines my function names, claiming they cannot be resolved. However, the code actually compiles, so I'm kind of at a loss as to why Eclipse thinks the functions are missing. If anyone has any idea on how to solve this problem it would be appreciated. Thanks beforehand.

我应该更具体,Eclipse 强调了 Arduino 库中的方法.因此,如果我使用 Serial.println("hello");,它会在 println() 下划线并声称无法解析.然后它编译得很好,当上传到 arduino 板时该方法有效.

I should have been more specific, Eclipse underlines the METHODS inside the Arduino libraries. So if I use Serial.println("hello");, it underlines println() and claims it cannot be resolved. Then it compiles just fine and the method works when uploaded to the arduino board.

我发现了我的错误,结果我试图在 C 文件中使用一些 C++ 函数,而 eclipse 不喜欢它;我重命名为 .cpp,所有红色都消失了 ;) 感谢您的帮助!

I found my error, turns out I was trying to use some C++ functions in a C file, and eclipse didn't like it; I renamed to .cpp and all the red disappeared ;) Thanks for your help!

推荐答案

对于初学者来说,下划线是什么颜色?这会有所不同,因为黄色表示警告,红色表示错误(严重,在大多数情况下不会构建).

For starters, what color is the underline? This makes a difference, as yellow means it's a warning, and red means it's an error (critical, will not build in most circumstances).

其次,您需要查看问题"选项卡以查看是否存在实际错误.如果那里什么都没有,那么它确实编译正确.

Second, you need to look at the "Problems" tab to see if there are actual errors. If there is nothing there, then it did indeed compile correctly.

现在,回到最初的问题.根据您正在构建的项目类型,这种类型的行为并不少见.Eclipse 似乎在索引某些项目方面做得很差.当您从命令行运行make all"(这实际上是 Eclipse 在构建期间所做的)时,它可能会解析您的所有代码并将其构建得很好.

Now, back to the original question. Depending on the type of project you are building, this type of behavior is not that uncommon. Eclipse seems to do a poor job of indexing certain projects. When you run "make all" from the command line (which is effectively what Eclipse does during build) it is likely resolving all of your code and building it just fine.

但是,Eclipse 使用一个不同的独立工具来索引所有源代码并解析变量/函数定义和声明.这实际上是左手不知道右手在做什么的情况.

However, Eclipse uses a different, separate tool for indexing all of your source code and resolving variable/function definitions and declarations. This is literally a case of the left hand not knowing what the right hand is doing.

这篇关于Eclipse C/C++ 显示错误但编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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