Eclipse Indigo CDT:无法解析功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7966976/
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-10 20:39:14  来源:igfitidea点击:

Eclipse Indigo CDT: Function could not be resolved

eclipseeclipse-cdt

提问by myk

This feels silly, but its been 2 days...somewhere after upgrading from Ubuntu 10.04 to 10.11 and from Eclipse Helios to Eclipse Indigo, I got stuck with the following problem:

这感觉很傻,但已经过了 2 天了……在从 Ubuntu 10.04 升级到 10.11 以及从 Eclipse Helios 升级到 Eclipse Indigo 之后,我遇到了以下问题:

Problem Description:

问题描述:

I'm trying to use a function in math.h called isinf(), but the problem also occurs with things like isnan().
The program compiles fine on the command line using make and fine in eclipse using build.
But if I open the program file in eclipse it reports that it cannot reolve the isinf() function call.
If I just insert the program contents into a new project and new source file, the error appears immediately.
This problem did not occur under 11.04 with Eclipse Helios CDT

我试图在 math.h 中使用一个名为 isinf() 的函数,但问题也出现在 isnan() 之类的东西上。
该程序在命令行上使用 make 编译得很好,在 eclipse 中使用 build 编译得很好。
但是如果我在 eclipse 中打开程序文件,它会报告它无法解决 isinf() 函数调用。
如果我只是将程序内容插入到新项目和新源文件中,则会立即出现错误。
使用 Eclipse Helios CDT 在 11.04 下未出现此问题

Questions:

问题:

Why are these errors only reported when the program file is opened and not on when the program is compiled; why are the errors not detected make is run from the command line?
Is there a solution/workaround available?

为什么这些错误只在程序文件打开时报,程序编译时不报;为什么未检测到错误 make 是从命令行运行的?
是否有可用的解决方案/解决方法?

Version Info

版本信息

Linux Ubuntu 10.11 64-bit
Eclipse CDT Indigo, Service Release 1, Build id: 20110916-0149
(Also using Eclipse EE Indigo – if that makes a difference)
GNU Make 3.81
gcc 4.6.1-9Ubuntu3

Linux Ubuntu 10.11 64 位
Eclipse CDT Indigo,Service Release 1,Build id:20110916-0149
(也使用 Eclipse EE Indigo——如果有区别的话)
GNU Make 3.81
gcc 4.6.1-9Ubuntu3

To Duplicate:

复制:

Please find the two files you'll need to replicate below:

请在下面找到您需要复制的两个文件:

Step 0.Verify that everything is fine outside of Eclipse
Copy the attached source file and make file
create a directory e.g. Mkdir FunTest
Save the source file a 'Test.cpp' and the makefile as 'makefile'
Open a command prompt and navigate to the directory e.g. FunTest
Enter 'make'
Enter ./TestOut
Program responds “is not infinite”

步骤 0.验证在 Eclipse 之外一切正常
复制附加的源文件并
生成一个目录,例如 Mkdir FunTest
将源文件保存为“Test.cpp”并将生成文件保存为“makefile”
打开命令提示符并导航到目录 eg FunTest
Enter 'make'
Enter ./TestOut
程序响应“不是无限的”

Step 1.Create the project in Eclipse
Open Eclipse
Select File|New|MakeFile Project with Existing Code
Click Browse – navigate to the directory (FunTest) and click ok
Select 'Linux GCC' from the Toolchain selector
Click Finish

步骤 1.在 Eclipse 中创建项目
打开 Eclipse
选择 File|New|MakeFile Project with Existing Code
单击 Browse – 导航到目录 (FunTest) 并单击 ok
从 Toolchain 选择器中选择“Linux GCC”
单击 Finish

Step 2.Find the Error
Click Build All (Ctrl-B) – project builds without errors
Open the project in the project explorer to display the file in the directory
Double click on the file “Test.cpp”
Note the error icon next to line testing for infinity
Note the 2 error messages:

步骤 2.找到错误
单击 Build All (Ctrl-B) – 项目构建没有错误
在项目资源管理器中打开项目以显示目录中的文件
双击文件“Test.cpp”
注意行旁边的错误图标测试无穷大
注意 2 条错误消息:

Semantic error: Function _isinff could not be resolved 
Semantic error: Function _isinfl could not be resolved

Test.cpp:

测试.cpp:

include <math.h>

int main(int argc, char **argv)
{

int TestNum = 10;

if (isinf(TestNum) == 0)
    printf("Not infinite\n");


return 0;

}

makefile:

生成文件:

# Specify the compiler
CC = g++

# Specify the compiler flags
CFLAGS += -c

# Specify the files making up the application
SOURCES = Test.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = TestOut

all: $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@

.cpp.o:
    $(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@

install:
    @echo "Build complete!"

回答by Fabian

I have experienced similar problems of the CDT reporting errors even though the code compiled fine within Eclipse Indigo.

即使代码在 Eclipse Indigo 中编译得很好,我也遇到过类似的 CDT 报告错误问题。

Project > Properties > Settings > Binary Parsers > "GNU Elf Parser"

项目 > 属性 > 设置 > 二进制解析器 > “GNU Elf Parser”

helped in my case. I had the "Elf Parser" checked.

在我的情况下有帮助。我检查了“精灵解析器”。

回答by Adam Miller

That looks like a problem that many others have had with eclipse CDT before. Sometimes shutting eclipse down and then starting it back up again is enough to help. If that isn't the case, take a look at what I have below:

这看起来是许多其他人以前在 eclipse CDT 上遇到的问题。有时关闭 eclipse 然后重新启动它就足以提供帮助。如果不是这种情况,请查看我下面的内容:

Compilation ok, but eclipse content assist having problems

编译正常,但是eclipse内容有问题

回答by tbellardi

Check your includes: if you're using include<math.h>change it to include<cmath>. The same for stdio.hand stdlib.h, you should replace by cstdioand cstdlib. Another option may be change you project to a C project instead of a C++.

检查您的包含:如果您正在使用,include<math.h>请将其更改为include<cmath>. 同为stdio.hstdlib.h,你应该更换cstdiocstdlib。另一种选择可能是将您的项目更改为 C 项目而不是 C++。

回答by Tomas Pruzina

You are missing -lm option in your build preferences. Project->Properties->Settings->Miscleanous->Other (linker) flags[]

您在构建首选项中缺少 -lm 选项。项目->属性->设置->错误->其他(链接器)标志[]

回答by andraaspar

For me, it was solved by adding a specific ‘Source Location' folder, and removing the default. In Luna, it is under:

对我来说,它是通过添加一个特定的“源位置”文件夹并删除默认值来解决的。在 Luna 中,它位于:

Project > Properties > C/C++ General > Paths and Symbols > Source Location

项目 > 属性 > C/C++ 常规 > 路径和符号 > 源位置