Eclipse C.D.T.无法识别标准功能或“NULL” [英] Eclipse C.D.T. can't recognize standard functions or "NULL"

查看:568
本文介绍了Eclipse C.D.T.无法识别标准功能或“NULL”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



尝试使用Eclipse或尝试使用纯GCC或G ++编译时,我已经遇到了这个问题了几个星期,并没有找到解决方案。通过一个终端,有一些标准函数(加上NULL变量)不能被识别,包括to_string方法。



我试图添加许多程序中的不同标头试图找到正确的文件,但无济于事。我试过 #including< string>,< stdio.h>,< stddef.h>,< cstdlib> ,几乎任何其他标准标题可以在论坛帖子中找到可能包含to_String函数的内容。我甚至尝试所有这些#includes与AND而没有.h扩展名。尽管如此,不管我尝试什么,to_string和NULL都没有被识别(除其他方法之外)。



我已经通过了许多论坛和许多论坛帖子,并尝试了许多解决方案,包括这一个这一个这一个这一个这个等等。我仍然没有找到解决方案。



我已经尝试卸载并重新安装Eclipse C.D.T.,Eclipse作为一个整体,GCC和G ++。我已经尝试在GCC命令或g ++命令中添加-std = c ++ 11和/或-std = c ++ 99标志。我已经尝试使用Linux GCC,Cross GCC和其他GCC版本在Eclipse中构建。



我正在运行Eclipse 3.8与J.D.T.和C.D.T.包装安装在64位Linux Mint 16 Petra上。



如果有任何人可以帮助我解决这个问题,感激不尽不会对你表示感谢。 >

编辑:
以下是 gcc -v 的输出:

 使用内置的规格。 
COLLECT_GCC = gcc
COLLECT_LTO_WRAPPER = / usr / lib / gcc / x86_64-linux-gnu / 4.8 / lto-wrapper
目标:x86_64-linux-gnu
配置为:。 ./src/configure -v --with-pkgversion ='Ubuntu / Linaro 4.8.1-10ubuntu9'--with-bugurl = file:///usr/share/doc/gcc-4.8/README.Bugs --enable -languages = c,c ++,java,go,d,fortran,objc,obj-c ++ --prefix = / usr --program-suffix = -4.8 --enable-shared --enable-linker-build-id - libexecdir = / usr / lib --without-included-gettext --enable-threads = posix --with-gxx-include-dir = / usr / include / c ++ / 4.8 --libdir = / usr / lib --enable- nls --with-sysroot = / --enable-clocale = gnu --enable-libstdcxx-debug --enable-libstdcxx-time = yes --enable-gnu-unique-object --enable-plugin --with-system -zlib --disable-browser-plugin --enable-java-awt = gtk --enable-gtk-cairo --with-java-home = / usr / lib / jvm / java-1.5.0-gcj-4.8- amd64 / jre --enable-java-home --with-jvm-root-dir = / usr / lib / jvm / java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir = / usr /lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory = amd6 4 --with-ecj-jar = / usr / share / java / eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32 = i686 --with -abi = m64 --with-multilib-list = m32,m64,mx32 --with-tune = generic --enable-checking = release --build = x86_64-linux-gnu --host = x86_64-linux-gnu - -target = x86_64-linux-gnu
线程模型:posix
gcc版本4.8.1(Ubuntu / Linaro 4.8.1-10ubuntu9)

以下是代码中出现错误的代码示例。请记住,我尝试添加其他#includes当前没有显示,我有理由相信缺少#include不是问题。

  #include< string> 
#include< stdio.h>
#include< iostream>

使用namespace std;

int Month [13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}

string x;

class Date_Time {
private:
int分,小时,日,月,年;
public:

Date_Time(int minute,int hour,int day,int month,int year){
this-> minute = minute;
this-> hour = hour;
this-> day = day;
this-> month = month;
this-> year = year;
}

string toString(){
string min = to_string(minute);
if(min.length()== 1)
min ='0'+ min;

return to_string(month)+/+ to_string(day)+/+ to_string(year)
++ to_string(hour)+:+ min;

}

void addMinutes(int min){

minute = min + minute;
if(minute> 59){
minute = minute - 60;
小时=小时+ 1;
}
如果(小时> 24){
小时=小时 - 24;
day = day + 1;
}

if(day> Month [month])
day = day - Month [month];
month = month + 1;

if(month> 12){
month = 1;
年=年+ 1;

}
}

int getYear(){
return year;
}

int getMonth(){
return month;
}

int getDay(){
return day;
}

int getHour(){
return hour;
}

int getMinutes(){
return minute;
}

};

编辑:下面的评论摘要是我们已经确定原因是Eclipse不是识别C ++ 11标准功能和关键字。我使用C / C ++插件在我的系统上安装了NetBeans,并且发生了完全相同的错误。尽管在项目配置中的多个地方添加了 -std = c ++ 11 标志,但我似乎无法让NetBeans或Eclipse识别C ++ 11功能。 / p>

到目前为止,Eclipse可以最终编译而不会给出C ++ 11错误;然而,在代码窗口中,C ++ 11的功能和功能仍被标记为带有红色下划线的错误,因此问题仍未完全解决。所有我需要的是有人告诉我如何让Eclispe和/或NetBeans在其错误解析器中识别C ++ 11功能。



提前再次感谢任何帮助您提供。

解决方案

尝试使用


$ b编译源代码$ b

  g ++ -std = c ++ 11 ... 

根据 to_string() ,它是一个C ++ 2011功能。






在Eclipse Kepler中,您可以通过选择

项目>>属性>> C / C ++ Build >>设置>>工具设置>> GCC C ++编译器>>方言



,并为语言标准选择 ISO C ++ 11(-std = c ++ 0x) / p>

您应该为配置选择 [所有配置] C / C ++ Build


I have been having this problem for weeks and have not been able to find a solution.

When trying to use Eclipse or trying to compile with plain GCC or G++ through a terminal, there are a number of standard functions (plus the "NULL" variable) that are not recognized, including the to_string method.

I have attempted to add many different headers to the program in an attempt to find the correct files, but to no avail. I have tried #including <string>, <stdio.h>, <stddef.h>, <cstdlib>, and pretty much any other standard header I could find in forum posts that might contain the to_String function. I even tried all of these #includes with AND without the ".h" extension. Still, not matter what I tried, to_string and NULL were not recognized (among other methods).

I've been through many forums and many forum posts and tried many solutions, including this one, this one, this one, this one, this one, and more. Still, I have found no solution.

I have tried uninstalling and reinstalling Eclipse C.D.T., Eclipse as a whole, GCC, and G++. I have tried adding -std=c++11 and/or -std=c++99 flags to the GCC command or g++ command. I have tried building in Eclipse with Linux GCC, Cross GCC, and other versions of GCC.

I am running Eclipse 3.8 with both J.D.T. and C.D.T. packages installed on 64-bit Linux Mint 16 Petra.

If anyone could help me resolve this issue, "grateful" would not properly express my gratitude toward you.

EDIT: Here is the output of gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9)

Here's a sample of the code the code that is having errors. Please keep in mind that I have attempted to add other #includes not currently shown and I have reason to believe that a missing #include is not the problem.

#include <string>
#include <stdio.h>
#include <iostream>

using namespace std;

int Month[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

string x;

class Date_Time {
private:
    int minute, hour, day, month, year;
public:

    Date_Time(int minute, int hour, int day, int month, int year) {
        this->minute = minute;
        this->hour = hour;
        this->day = day;
        this->month = month;
        this->year = year;
    }

    string toString() {
        string min = to_string(minute);
        if (min.length() == 1)
            min = '0' + min;

        return to_string(month) + "/" + to_string(day) + "/" + to_string(year)
                + " " + to_string(hour) + ":" + min;

    }

    void addMinutes(int min) {

        minute = min + minute;
        if (minute > 59) {
            minute = minute - 60;
            hour = hour + 1;
        }
        if (hour > 24) {
            hour = hour - 24;
            day = day + 1;
        }

        if (day > Month[month])
            day = day - Month[month];
        month = month + 1;

        if (month > 12) {
            month = 1;
            year = year + 1;

        }
    }

    int getYear() {
        return year;
    }

    int getMonth() {
        return month;
    }

    int getDay() {
        return day;
    }

    int getHour() {
        return hour;
    }

    int getMinutes() {
        return minute;
    }

};

EDIT: The summary of the comments below is that we have determined that the cause is that Eclipse is not recognizing C++11 standard functions and keywords. I installed NetBeans on my system with their C/C++ plugin and the exact same errors are occurring. I can't seem to get NetBeans or Eclipse to recognize C++11 features despite adding the -std=c++11 flag in multiple places in the project configurations.

As of right now, Eclipse can finally compile without giving C++11 errors; however, in the code window, C++11 functions and features are still marked as errors with a red underline, so the issue is still not completely resolved. All I need is for someone to tell me how to get Eclispe and/or NetBeans to recognize C++11 features in its error parsers.

Thanks again in advance for any help you may be able to provide.

解决方案

Try to compile your source code with

g++ -std=c++11 ...

According to to_string(), it is a C++ 2011 feature.


In Eclipse Kepler, you could set this by selecting

Project >> Properties >> C/C++ Build >> Settings >> Tool Settings >> GCC C++ Compiler >> Dialect

and choosing ISO C++11 (-std=c++0x) for Language standard.

And you should choose [All configurations] for Configuration at C/C++ Build.

这篇关于Eclipse C.D.T.无法识别标准功能或“NULL”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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