1

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.

Community
  • 1
  • 1
Variadicism
  • 624
  • 1
  • 7
  • 17
  • Can you share the version of your gcc(gcc -v). – Mantosh Kumar Mar 25 '14 at 03:15
  • Please include an example source file that can be used to reproduce your problem in your post. – Lee Duhem Mar 25 '14 at 03:18
  • My version is 4.8.1. I'll edit the original question to show the entire output of `gcc -v` since it's too big to paste in this comment. – Variadicism Mar 25 '14 at 03:19
  • I will also add a sample of the code. – Variadicism Mar 25 '14 at 03:20
  • I added a sample of code and the full output of gcc -v. Also, one of the other methods not recognized in addition to to_string and NULL is strcmp/stricmp. – Variadicism Mar 25 '14 at 03:42
  • If using C++11, code `nullptr` instead of `NULL` – Basile Starynkevitch Mar 25 '14 at 06:11
  • All right. I've done some more searching and researching and testing and I think that the problem is that Eclipse can't recognize c++11 methods and tools, including NULL, nullptr, to_string(), strcmp(), stricmp(), and free(). @leeduhem suggested one way of getting Eclipse to recognize c++11, but it did not work for me. Any one know how to make Eclipse 3.8 recognize and use c++11 libraries? – Variadicism Mar 25 '14 at 19:48

1 Answers1

1

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.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
  • I did that before, but I tried it again to make sure. It's hard to say whether or not it worked in the terminal, but Eclispe still calls to_String an error, claiming "Function 'to_string' could not be resolved". – Variadicism Mar 25 '14 at 04:15
  • @REALDrummer What is the `g++` options given by your Eclipse? – Lee Duhem Mar 25 '14 at 04:29
  • In Project >> Properties >> C++ Build >> Settings >> Tool Settings >> GCC C++ Compiler >> Miscellaneous, I have the flags listed as `-c -fmessage-length=0 -std=c++11`. – Variadicism Mar 25 '14 at 04:34
  • @REALDrummer Try this: Project >> Properties >> C++ Build >> Settings >> Tool Settings >> GCC C++ Compiler >> Dialect >> Language standard, and choose `ISO C++11`. – Lee Duhem Mar 25 '14 at 05:31
  • I changed my Configuration to "[All configurations]" and it did not change anything visibly. As for the "Language Standard" setting, it appears Eclipse 3.8 differs from Kepler here. I went to the "GCC C++ Compiler" setting directory you referred to, but I found no "Dialect" or "Language Standard" settings there. – Variadicism Mar 25 '14 at 15:38
  • @REALDrummer Add `-std=c++11` in "Miscellaneous" works in Eclipse 3.8. If you run `Project >> Build Project`, you should be able to see in "Console" the actual `g++` command line options used by Eclipse. – Lee Duhem Mar 26 '14 at 13:56
  • Okay. @leeduhem Good news and bad news. I've tried adding that `-std=c++11` flag before to no avail, but I checked the command line options that appear in the console during runtime like you suggested. I did get the flag to actually appear there now (I'm not sure why it wasn't before) and the errors saying methods like `to_string()` aren't recognized have disappeared in the compiler. However, the bad news is that Eclipse still marks them as errors in the code window. – Variadicism Mar 26 '14 at 16:21
  • Since Eclipse C.D.T. was having these issues, I tried installing NetBeans with their C/C++ plugin to see if it would work any better. NetBeans had the same errors as Eclipse. I just can't seem to get either of them to recognize C++11 features. – Variadicism Mar 26 '14 at 17:12
  • @REALDrummer Those error marks are made by the static code analyzer, however I do not know how to make them recognize C++11 features. – Lee Duhem Mar 26 '14 at 17:24
  • Okay. Thanks for your help thus far. I'm going to probably make a new question to rephrase and reorganize the question based on what you've helped me figure out so far. – Variadicism Mar 26 '14 at 17:57