3

Please read this question before marking it as a duplicate!

This question is not a duplicate of this question or this question or this question, though it is related. I have been through all of these questions and many more. I have the same basic problem, but I have tried all the solutions I have found and none of the solutions to these other questions have worked for me.

The issue is that Eclipse C.D.T. does not recognize many C++ standard functions and features. Most of these features that are not recognized are from C++11. Unrecognized features include the keyword nullptr, the variable NULL, and the functions to_string(), getLine(), fstream.open(), atoi(), strcmp(), stricmp(), and more.

With the help of a user named leeduhem and others, I managed to add the -std=c++11 flag to Eclipse's g++ compiler command, so the errors during compilation disappeared.

However, Eclipse still underlines these methods and symbols in red and marks them as errors.

So, my question, in summary, is:

How can I get Eclipse to recognize C++11 functions and symbols in the code editor?

I have tried all the solutions in the questions linked above as well as the solution in Eclipse's C++11 F.A.Q. with and without the modification mentioned in this forum post. Still, nothing works.

I recently installed NetBeans on my computer with the C/C++ plugin to try and remedy the issue by switching I.D.E.s, but NetBeans had the exact same errors.

I am running Eclipse 3.8 on Linux Mint 16 Petra. My primary compiler is GCC/G++ 4.8.1, though I believe I also have Cygwin available.

Here is a sample of the code that is having errors:

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

using namespace std;

HubNode* hubs;

void debug();
void menu();

// main
int main() {
    // initialize hubs
    hubs = NULL;

    // read Hub.csv
    fstream hub_in;
    hub_in.open("Hub.csv", ios::in);
    if (!hub_in.is_open()) {
        cout << "I couldn't open the Hub.csv file!";
        return -1;
    }
    string read_name = "", read_location = "";
    // skip the first line
    getLine(hub_in, read_name);
    if (read_name.empty()) {
        cout << "The Hub.csv file was empty!";
        return -1;
    }
    // then continue reading
    while (getLine(hub_in, read_name, ',')) {
        getLine(hub_in, read_location, '\n');
        addHub(new HubNode(read_name, read_location));
    }

    // read Flight.csv
    fstream flight_in;
    flight_in.open("Flight.csv", ios::in);
    if (!flight_in.is_open()) {
        cout << "I couldn't open the Flight.csv file!";
        return -1;
    }
    string read_number = "", read_price = "", read_source = "",
            read_destination = "", read_minute = "", read_hour = "", read_day =
                    "", read_month = "", read_year = "", read_duration = "",
            read_company = "";
    // skip the first line
    getLine(hub_in, read_number);
    if (read_number.empty()) {
        cout << "The Hub.csv file was empty!";
        return -1;
    }
    // then continue reading
    while (getLine(flight_in, read_number, ',')) {
        getLine(flight_in, read_price, ',');
        getLine(flight_in, read_source, ',');
        getLine(flight_in, read_destination, ',');
        getLine(flight_in, read_minute, '/');
        getLine(flight_in, read_hour, '/');
        getLine(flight_in, read_day, '/');
        getLine(flight_in, read_month, '/');
        getLine(flight_in, read_year, ',');
        getLine(flight_in, read_duration, ',');
        getLine(flight_in, read_company, '\n');
        FlightNode* flight = new FlightNode(read_number,
                atof(read_price.c_str()), read_company,
                new Date_Time(atoi(read_minute.c_str()),
                        atoi(read_hour.c_str()), atoi(read_day.c_str()),
                        atoi(read_month.c_str()), atoi(read_year.c_str())),
                atoi(read_duration.c_str()), read_source, read_destination);
    }

    cout << "Welcome to Ground Control! How may I assist you?";
    menu();
    string input;
    cin >> input;
    cin.ignore();
    while (strcmp(input.c_str(), "q") != 0) {
        if (strcmp(input.c_str(), "p") == 0)
            debug();
        else {
            // TODO
        }
        cin >> input;
        cin.ignore();
    }
    cout << "Have a nice flight!";

    return -1;
}

// message utilities
void debug() {
    HubNode* hub = hubs;
    while (hub != NULL)
        cout << hub->toString();
}

void menu() {
    cout << "cmd | description";
    cout
            << " p | prints the full list of airport hubs with all of their currently scheduled flight information";
    // TODO
}

// Hub-managing utilities
bool addHub(HubNode* hub) {
    // if hubs is null, make this hub the new head
    if (hubs == NULL) {
        hubs = hub;
        return true;
    }

    // otherwise, find the end of the hubs list and add this hub to the end
    HubNode* parser = hubs;
    while (parser->next != NULL) {
        // along the way, make sure this hub isn't already in the list
        if (strcmp((parser->getName()).c_str(), (hub->getName()).c_str()) == 0)
            return false;
        parser = parser->next;
    }
    parser->next = hub;
    return true;
}

HubNode* findHub(string name) {
    HubNode* parser = hubs;
    while (parser != NULL) {
        if (strcmp((parser->getName()).c_str(), name.c_str()) == 0)
            return parser;
        parser = parser->next;
    }

    return NULL;
}

bool removeHub(HubNode* hub) {
    return removeHub(hub->getName());
}

bool removeHub(string name) {
    // check the first node alone first
    if (hubs == NULL)
        return false;
    else if (strcmp((hubs->getName()).c_str(), name.c_str()) == 0) {
        HubNode* to_remove = hubs;
        hubs = hubs->next;
        delete to_remove;
        return true;
    } else if (hubs->next == NULL)
        return false;

    HubNode* parser = hubs;
    while (parser->next != NULL) {
        if (strcmp((parser->next->getName()).c_str(), name.c_str()) == 0) {
            HubNode* to_remove = parser->next;
            parser->next = parser->next->next;
            delete to_remove;
            return true;
        }
        parser = parser->next;
    }

    return false;
}

Any ideas?

Thank you in advance for any help you can provide. I'm pretty desperate at this point. This issue has greatly hindered my progress on a C++ class project and I am not nearly experienced enough to try and code in it without an I.D.E. (I've tried.)

EDIT: It seems that there are a few functions that even g++ can't recognize when compiling from the terminal, e.g. stricmp(). I am yet unsure if there are any others, though it seems to be able to understand to_string and some others. My G++ version is 4.8.1, though, which is almost the latest stable version.... Could this be causing the errors in Eclipse and NetBeans?

Community
  • 1
  • 1
Variadicism
  • 624
  • 1
  • 7
  • 17
  • maybe try Qt, it works with C++11 – 4pie0 Mar 26 '14 at 18:26
  • @lizusek What is Qt and how do I use it in Eclipse? I haven't seen anything about a "Qt" in Eclipse's settings anywhere.... – Variadicism Mar 26 '14 at 19:19
  • I'm not familiar with `getLine()` from C++11. As far as I know, there are no standard library facilities and only a few preprocessor facilities (largely inherited from C and usually beginning with an underscore-capital) that use CamelCase in identifiers. – Adam H. Peterson Mar 26 '14 at 19:23
  • @REALDrummer [Qt Creator](https://qt-project.org/search/tag/qt~creator) is another IDE – 4pie0 Mar 26 '14 at 19:24
  • There is no Eclipse 3.8 version - http://wiki.eclipse.org/Older_Versions_Of_Eclipse. Did you try to use Eclipse 4.3.2 with CDT 8.3? – Dmitry Sokolov Mar 26 '14 at 19:36
  • It seems that the NetBeans 7.4 and Eclipse CDT IDEs are not completely current with the latest C++11 keywords. I tried a couple minor things with NetBeans 7.4 on the `__GXX_EXPERIMENTAL_CXX0X__ = 1` macro and the purposeful addition of the `\usr\lib` path in the Code Assistance tab. Neither worked to correctly acknowledge the C++11 `override` keyword inside the IDE editor. – CPlusPlus OOA and D Mar 26 '14 at 19:45
  • @DmitrySokolov When I boot up Eclipse, it says Eclipse 3.8, so there is, in fact, an Eclipse 3.8. It's possible the list you found is for Windows versions, while I'm using a Linux version. In any case, I **am** using Eclipse 3.8. The C.D.T. version is listed as 8.1.2-2 on Linux Mint's Software Manager. – Variadicism Mar 26 '14 at 19:56
  • @CPlusPlusOOAandD I, too, tried adding that `__GXX_EXPERIMENTAL_CXX0X__` symbol and adding more includes, but it did not work for me either. :( This issue is really killing me. – Variadicism Mar 26 '14 at 20:00
  • @lizusek I see. Well, I would love to get Eclipse working since I'm familiar with its interface and quirks and all, but I will keep your suggestion in mind in case I can't manage to fix Eclipse. – Variadicism Mar 26 '14 at 20:01
  • @REALDrummer Have you tried the more recent version? The main Eclipse CDT page says 8.3.0 is now available (since February 28, 2014). – CPlusPlus OOA and D Mar 26 '14 at 20:05
  • I do use Eclipse 4.3 on Ubuntu. I downloaded the .tar.gz file and unpacked it to /opt/eclipse. The version provided by packet manager is not fresh. – Dmitry Sokolov Mar 26 '14 at 20:09
  • @DmitrySokolov All right. I installed the newest Eclipse I could find from the website using the install guide I found on [this AskUbuntu question here](http://askubuntu.com/questions/26632/how-to-install-eclipse) then used the built-in software manager to add C.D.T. Unfortunately, the same errors is still occurring and I noticed that in the settings for the newest Eclipse, the `-std=c++11` flag is already included by default. – Variadicism Mar 26 '14 at 20:51
  • @CPlusPlusOOAandD As I mentioned to Mr. Sokolov above, I have installed the newest Eclispe tar.gz form the Eclispe website, but the same error occurs. I'm starting to wonder if it's possible that my GCC/G++ is out of date...? I have the newest version from the Software Manager, but as you guys just showed me, the Software Manager's software is very out of date. – Variadicism Mar 26 '14 at 20:53
  • @REALDrummer I am wondering the same thing. You may have to obtain an Eclipse build / installation directly from [Eclipse IDE for C/C++ Developers](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/keplersr2). The download links for the different OSs are on the right. Here is the page for: [CDT Downloads](http://eclipse.org/cdt/downloads.php) – CPlusPlus OOA and D Mar 26 '14 at 21:09
  • @REALDrummer The NetBeans 7.4 IDE may not be smart enough about C++11 keywords. However, it will correctly compile, run, and test with CppUnit on the CLang++ 3.3 compiler. I have done so on Mac OS X Mavericks with the Xcode Command Line Tools (ultimately CLang++ 3.3). Apple replaced / updated from GCC 4.2 with the LLVM compiler (CLang). – CPlusPlus OOA and D Mar 26 '14 at 21:22
  • @REALDrummer The posted answer below has been revised with an Eclipse toolchain article from the ARM Technical Support Knowledge Articles site. – CPlusPlus OOA and D Mar 27 '14 at 16:29
  • @DmitrySokolov So...Eclipse just started working today. I don't know what changed.... Maybe installing the new Eclipse modified something in my workspace configuration that fixed it and maybe my computer needed to be restarted for that change to take effect. Anyway, thanks for all your help. – Variadicism Mar 27 '14 at 20:30

1 Answers1

1

Most likely the Eclipse and NetBeans IDEs have to have an updated parser and lexer details to correctly support C++11. Hopefully someone has already done this for C++11 and can post additional details.

It appears NetBeans is written in Java, since that product's forum has three posts that discuss the procedure for older and more recent NetBeans versions.

Start Edit
I have found a non Eclipse post that may be the solution for C++11 keyword recognition inside the Eclipse IDE. Review: How do I use a custom gcc toolchain with Eclipse?. It has a step by step procedure and screen captures for updating the GCC toochain within Eclipse. I expect support from the CLang and CLang++ compiler set to be similar. The external article is from this SO post: Eclipse IDE for C++ hooking up multiple compiler toolset
End Edit

I do not have additional time right now to follow the NetBeans procedure to create a new NetBeans parser and lexer for the C++11 support. Maybe someone else has already done so and can share the details. The posts I have found follow. Note, that these are tutorials for any language in the NetBeans IDE.

Both of the above steps must occur in this order. If not, I have no idea what will happen, but likely not the expected outcome.

I wish more complete posts exist. Maybe the other users are simply ignoring the incorrect keyword indications from the IDEs. NetBeans 7.4 seems perfectly fine compiling with the CLang++ 3.3 compiler. I have no C++11 compilation errors on a C++11 centric project. The IDE is improperly saying that override is invalid though.

Community
  • 1
  • 1
  • Thanks a lot for all your help. After all this, I booted up Eclipse today, and it started working.... I have no idea what changed, but I guess something that I tried worked. I hadn't even gotten around to trying these solutions yet, but thank you anyway for taking the time to post them! I hope someone who finds this question will find this answer helpful in the future. – Variadicism Mar 27 '14 at 20:28