I am very new to coding C++ and to using the Netbeans IDE. Worse yet, I'm on a Mac (but I can't imagine that's the source of the issue this time).
The IDE is giving me countless nonsense "hints" as in red exclamation mark symbols, most of which say "Unexpected token" for things like ';' at the end of a statement or '=' in a statement. These are of course ridiculous because, as I understand c++ so far, they are necessary for even the most basic statements!
screenshot here
What could possibly be causing this and how do I get rid of the hints or, preferably, fix something if there is an error somewhere?
Delete your Netbeans cache. In my case the problem when away when I did this. I think I initially ended up in this state because my C++ project was under a Java project. After separating the two the error was still present even with a clean/build. Deleting the Netbeans cache got rid of the problem. Even if your situation is different you should try this. Clearing the Netbeans cache once in a while fixes a lot of issues.
Tyler,
I'm going to go out on a limb and guess that you've got your Net beans ide setup to use another language other than C++. Remake the project and make sure your using c++
I had the same issue.
The issue was, I wrote C++14 code, in the C++ project.
To resolve this:
- Create a C++14 project (Select from the drop down, while creating the project)
- Add existing C++ files to it
Hope that helps.
Related
I'm trying to learn how to use Eclipse for C++ development (using MinGW) and have run into an interesting problem.
While writing a simple test program I get the following error:
However simply saving the file resolves the error... Why does this happen?
After saving:
I would really like simple bugs like this to be caught without having to go and manually save the file...
I know it's really simple to just click "Save" but I know myself and I will forget and I will spend hours trying to track down a bug that isn't actually a bug. (I'm sure this will probably also happen with things other than using namespace std;.)
Eclipse's CODAN tool runs as you type, unfortunately it only parses dependencies on demand, usually with a save.
Why? Eclipse's CODAN tool isn't exactly a gazelle, so having to track through all of the file's dependencies while the user is typing is probably a system killer. This may improve with time. In the meantime, save regularly.
And, to be honest, this is probably a dodge. It should only have to search dependencies when a dependency is added. But there are a lot of buts. What about when a dependency is added to a dependency? Or a new dependency is hidden in a macro (don't do this) and hard to parse without digging through the dependencies? Or exposed by adding a define that triggers conditional compilation (I prefer different implementation files and letting the linker sort it out to conditional compilation)? What about...?
Blah. If people want to write garbage code, that's their problem. A static analyzer should focus on the needs of people who aren't trying to trick it and circumvent good style. That said, I don't know the CODAN code, and I don't know how deep one would have to go to change it to catch and handle the easy cases at a tolerable real-time rate.
But at the end of the day, the only analyzer you should pay attention to is the compiler--with the warning levels turned up to 11, of course. CODAN is not perfect. It misses and misinterprets stuff, and you may find yourself hunting a bug that's not a bug in your code. If the compiler has a bug, that's a different case, but a lot less likely. Definitely take CODAN's help, but before you spend time on an odd error, make sure it really is an error by saving and building the program.
CODAN configuring stuff:
Most of CODAN's options can be found by visiting Project->Properties on the menu and navigate the Properties dialogue to C/C++ General->Code Analysis
To turn configure CODAN's run options, to turn off updating as you type for example, go one step further to C/C++ General->Code Analysis->Launching
You will also find that if you are editing included headers in another project, you will have to force an index rebuild to to catch the modifications. Select Project->C/C++ Index->Rebuild from the menu for the project doing the including.
I have some troubles with Embarcadero C++ Builder XE3. When I run my program, I have an access violation BEFORE the first instruction in the main...So I can't debug, it's very weird.
I used to have this problem a couple of weeks ago : I was forced to full rebuild the entire projet (even if only a comma was missing...) and the violation didn't occurs anymore. I solved it by ckecking the option "Disable incremental link".
I was very happy, but today, the problem is back, and whatever I do, my application crash before enterring in the main ...
Does anyone have an idea ? It's a big project, so I can't really post an exemple because I don't really know what to show...
Thanks a lot
Probably you have a bug in a constructor of a static global object. These constructors are all executed before getting into main(), so this can happen without being a runtime environment or a compiler bug.
As you told, debugging these is difficult as you probably don't know which class is failing, and probably you don't have exception info also.
As you say it's a large project, perhaps you have to resign to use large project toolkits/methodologies to deal with these problems, like unit testing and lean methodologies (like scrum or the like).
With the information you post I think this is the most can be said.
I am having a weird bug in using netbeans and C/C++ plugin along with that.
When I copy/paste a code, it gives me error Unable to resolve identifier on every function (including main). But if i manually type same code/program, its all good and working and compiles/runs perfectly. Can anyone explain that to me? Normal java projects work just fine (the copy/pasting code doesnt give any sort of error), its just the problem with C/C++ projects (havent tried others yet). I not only want to know solution, but also the possible cause (out of curosity).
EDIT:
Here's an example of an infinite loop i was trying (say for fun? lol)->
#include <stdio.h>
int main()
{
char a;
for(a=32;a<128;a=a+1)
printf(“%3d = ‘%c’\t”,a,a);
return(0);
}
This program goes on displaying keyboard characters and their ASCII codes over and over endlessly. If I manually type this program, its all good. If I copy paste this code, it gives me error as stated above (on every variable and function. For ex- "Unable to resolve identifier" on main function).
Some backstory (not related to problem really)...
Actually I am using netbeans because of its features. The way it tells about a lot of errors right on real-time bases, its auto bracket closing feature, the ui cleanliness (or maybe I am used to it). I just started leaning C a while ago, though I am quite advanced in java (the reason I have netbeans, I dont use eclipse because of drag and drop interface, which basically cuts a lot of time for me. I know there are plugins now that enable that in eclipse too, so I might give it a try but for now I am used to netbeans' interface). My teacher recommended me bloodshed C/C++ (which i didnt like, its like a plain notepad with just the ability to compile) or turbo C (which proves my teacher to be of ancient times). And he told me visual studio was too advanced for me right now. So i decided to stick with netbeans. Except this problem, everything is working perfect as of whatever I have tried right now.
Also, as of side note, do you guys think me sticking with netbeans for C/C++ for now is ok (ok in sense I am wondering about the cons)? I think I'll move on to visual studio later....
The code you have in your question won't compile on any compiler. Why?
You are using curly quotes here:
printf(“%3d = ‘%c’\t”,a,a);
“ and ” are different from ". Use " instead of “ and ” to fix the problem.
‘ and ’ might also cause problems. Replace them with '
I've been re-learning c++. I haven't coded in c++ for quite a few years, although I really like the language, so I decided that I would re-learn it. When I first learned c++ I used dev c++ as ide. Nowadays it is seriously deprecated and I decided to use netbeans since it's the one I use for java and I'm quite accustomed to work with it.
I've set everything up in the ide, downloaded the plugin and installed the compiler and stuff. I'm having, though, a very frustrating time with the warnings of netbeans. The code itself compiles and runs fine, but netbeans doesn't seem to work very well. For example, if I create a new source file and before any compiling I write the usual using namespace std; there's a red wavy underline under std where netbeans gives the following error message "unable to resolve identifier std". If I then compile the code it disappears and everything is fine so it's not a serious problem , although it's quite an annoying behaviour.
Another, not so simple, error is if I declare a variable say int x;. I then use the variable x throughout the code, everything's fine. But if by some reason I delete the declaration statement (sometimes it happens), the rest of the code, which should by full of error messages, appears has everything's fine, no wavy red underlining...
It appears to me that netbeans only notices the errors after I compile the code... Does someone know how to fix this behaviour?
This is normal (there is nothing wrong with Netbeans).
When editing java code, the IDE parses the code as you type and corrects immediately (or, with a relatively short delay).
When editing C++, the language is a lot more complex than Java, and while the IDE finds some errors (and underlines them), a lot of them are in code that is too complex to be parsed instantly (C++ compilation is difficult to do, and even more so, to do fast). As such, Netbeans relies on you compiling the code to update error information.
I have been stumbling through some different steps to do this. I ran the qt3to4.exe on the files with compile errors and got though a lot of conversion steps, however now I am getting this error:
1>c:\qt\4.7.0\src\qt3support\widgets\q3toolbar.h(64) : error C2039: 'ToolBarDock' : is not a
member of 'Qt'
and 55 other similar errors. This confuses me since it is in qt's own q3support library. I also saw on a QT help page (http://doc.trolltech.com/4.2/qt-qt3.html) that ToolBarDock is deprecated and Qt::Dock should be used instead.
I haven't found much help on this out there. I'm using the library inside Visual Studio 2008. Any QT/visual studio experts out there?
If this helps, here is the code it is failing on in q3toolbar.h:
Q3ToolBar(const QString &label,
Q3MainWindow *, Qt::ToolBarDock = Qt::DockTop,
bool newLine = false, const char* name=0);
Actually qt34qt4 doesn't do all things right. There are many methods, enums etc, which are not converted. It is more or less simple find-replace tool which replace following instructions from qt\tools\porting\q3porting.xml
In many cases there is a replacement definition for a class, but not for a method of this class. In some cases qt3to4 replaces enums and methods in code which doesn't belong to Qt-classes at all. So be carefull. In any case, I would suggest getting a list of all Qt classes in you code, read carefully porting notes (http://doc.qt.nokia.com/4.5/porting4.html) for each class you use.
Another issue are return types, qt3to4 doesn't check how the returned value is used. Fortunate qt3to4 makes a good job, so fixing the rest is often a trivial, repetitive task.
If you have to port UIs, take a look at undocumented argument -wrap of uic3.
P.S.: Some figures for your effort estimation, may be usefull: I've ported (got compiled) once 600TLOCs + 150 UIs in 2,5 Months, currently I am porting about 150 TLOCs project and got pretty far in 2 weeks.
I had these errors as well after importing a project into VC++. Adding QT3_SUPPORT to the preprocessor definitions fixed it.
I ended up going a different route on this problem. I found the implementations I needed from the "qt3 library" somewhere else. Just before I found that out, I got some advice from some coworkers here. The consensus was that I'd need to rebuild Qt specifying to include qt3 support. Although I didn't follow through with this, here are some helpful links.
http://www.qtcentre.org/wiki/index.php?title=Qt4_with_Visual_Studio
http://lists.trolltech.com/qt-interest/2006-11/thread00177-0.html
If anyone comes across this and gets through this problem, please post your solution! Thanks.