Thanks for taking the time to read my question. Sonar-scanner analysis is successful but these warnings are printed on the screen. The team, being very new to Sonar and I, not knowledgeable enough in C++, are both stumped.
Sonar-scanner message:
WARN: [/home/jenkins/workspace/Sonar/LIS/src/CORE/CCPARSE/lib/Factory.C:39]: syntax error, skip '__namespace'
for other files containing the namespace block, everything in the namespace block are displayed as syntax errors. Files without the namespace block are fine. The team needs the namespace blocks.
The actual code in Factory.C:
#include <CCPARSE/Factory.H>
namespace CCPARSE {
Needless to say, if I comment out the namespace line and its closing brace, the warning goes away.
The file is analyzed in Sonar though. I can see the file mentioned in the analysis as well as a calculation of duplicated code, etc.
Thanks to a wise gentleman on GitHub, I figured out the issue. namespace is a functionality of C++ and not of C . Once I renamed the files as .cpp instead of .C, the syntax error went away!
Related
First of all thank you for taking the time to read and maybe answer this.
I want to include a compressed font, which has been converted from a .ttf file into a .h file.
The compressed font is saved (in the .h file) inside an array of the type:
static const unsigned int font_name_compressed_data[about 3 - 10 thousand]
For what I am using (ImGui) this is all fine and I can import the font correctly.
The problem is, when i want to encapsulate those font_name_compressed_data arrays (one for each font) within an namespace, intellisense suddenly stops recognizing them.
It still compiles fine, but intellisense does not work and it constantly shows that there are still errors.
I am using c++17 although i don't think that matters.
And I am compiling with Visual Studio 2019, while editing with Visual Studio Code.
Did I do it wrong the first time or is this a bug from intellisense?
~~ E D I T :
My assumption was wrong, after manually opening every font_name.hpp file and individually adding the namespace to it, intellisense was working again. But after closing and reopening it, the same error came back. It is either this
namespace "Fonts" has no member "roboto_compressed_data"
or this
name followed by '::' must be a class or namespace name
seemingly random.
If I autocomplete Fonts:: in Visual Studio 2019 I get all my fonts, but if I do the same thing in Visual Studio Code I dont get any, unless I manually open the font header file in Visual Studio Code and close it again.
Also the error comes back after doing Rescan Workspace.
I think I have my project set up right, since I don't get an error anywhere else when using namespaces or includes.
Seems like VS Code just unloads the font header file from memory or something, since it is pretty long, but I don't know...
When i do it like this it does not get recognized:
in the compressed_font.h
static const unsigned int font_name_compressed_data[size of the array] =
{ 0x0000bc57, 0x00000000, 0x78b30000, ... and so on }
where i then want to use it (.cpp):
namespace font_data
{
#include "compressed_font.h"
}
// ...
// v--- This is then unrecognized
font_data::font_name_compressed_data
But after i changed everything to this it got recognized again:
in the compressed_font.h
namespace font_data
{
static const unsigned int font_name_compressed_data[size of the array] =
{ 0x0000bc57, 0x00000000, 0x78b30000, ... and so on }
}
where i then want to use it (.cpp):
#include "compressed_font.h"
// ...
// v--- This is now recognized
font_data::font_name_compressed_data
My aunt gave me a book about c++ (for beginners). It's nice and so I wanted to test one of those code samples. But I am just getting errors. I didn't find anything that could help me on Google or so.
I am using Eclipse Mars.1 C++ and MinGW.
Code:
/*
* Erstes_Programm.cpp
*
* Created on: 26.12.2015
* Author: Luca
*/
// Erstes Programm
#include <iostream>
using namespace std;
int main() {
cout << "It's just a test!" << endl;
return 0;
}
I am getting those errors:
Using namespace:
Description Resource Path Location Type
expected ';' before ':' token
Erstes_Programm.cpp /Programmieren C++ (Einführung)
line 10
C/C++ Problem
AND
Description Resource Path Location Type
expected unqualified-id before ':' token
Erstes_Programm.cpp /Programmieren C++ (Einführung)
line 10
C/C++ Problem
Hope somebody can help me?
Here is a screenshot:
EDIT: PROBLEM SOLVED!! I don't know WHAT I did, but it's solved I'm not getting any errors and everything works perfectly. Thanks for everybody who wanted to help
The first line in the screenshot doesn't make any sense. Remove it. The rest looks fine. And in the future, post text, not screenshots.
Instead work on X-code rather then eclipse for C++. Visual studio is most recommend.
For Your problem, I think you got to play with the library, something must not be supported, other then that your code look fine.
I have been using the allegro 5 libraries for developing a game in C++ for some time. Today I got some weird error:
I have a class called level. I have a header file called levelhandler.
Here's how it looks:
#pragma once
#include "level.h"
level level_1;
level *currentlevel;
void initialize_levels()
{
currentlevel = &level_1;
}
When I try to compile it gives me strange errors like:
error C2086: 'int level' redefinition
error C2143: syntax error : missing ; before 'level_1'
I remember that it could compile before, and I did use currentlevel->Player.X a lot of times, but now I have a lot of that and it gives errors like these:
error C2227: left of '->Player' must point to a class/struct/generic type
error C4430: missing type specifier - int assumed
header pasted from comment
#pragma once
#include "entity.h"
// some more includes
class level {
public:
enum Tileset { ... };
enum Tile { ... };
int tiles[200][200];
player Player;
level(void);
~level(void);
};
Such errors are hard to find as long as you look at the "Error List" pane. Select View/Output to show the "Output" view. The line after the error C2086 shows the original definition of level.
You fill find an
int level;
there as the C2086 tells you. If it's the line
level level_1;
of your fist example you will have to check the last header file include in your compilation unit. It might end with an int or it has a unbalanced #if clause.
To find the exact location start using a Short, Self Contained, Correct (Compilable), Example. This helps you to find the bug and saves time of other with their crystal balls.
Edit:
Another way to find the reason for this unexpected behavior is to see the preprocessor output. Set the Generate Preprocessed File option int the C/C++/Preprocessor project property page to With line numbers (/P) and look in the generated <sourcefile>.i
Check that that level.h file has included what you intended.
Ok, so I've been tinkering around with my project the weekend, and I finally found out what whas the problem that gave me so many weird compiler errors. It seems that I had a lot of cases where two header files were including each other, and the compiler really didn't like that, so I corrected that, and now I'm ok. Thank you all for helping me, and have a great day!
I have reinstalled emacs 24.2.50 on a new linux host and started a new dotEmacs config based on magnars emacs configuration. Since I have used CEDET to some success in my previous workflow I started configuring it. However, there is some strange behaviour whenever I load a C++ source file.
[This Part Is Solved]
As expected, semantic parses all included files (and during the initial setup parses all files specified by the semantic-add-system-include variables), but it prints this an error message that goes like this:
WARNING: semantic-find-file-noselect called for /usr/include/c++/4.7/vector while in set-auto-mode for /usr/include/c++/4.7/vector. You should call the responsible function into 'mode-local-init-hook'.
In the above example the error is printed for the STL vector but a corresponding error message is printed for every file included by the one I'm visiting and any subsequent includes. As a result it takes quite a long time to finish and unfortunately the process is repeated any type I open a new buffer.
[This Problem Is Solved Too]
Furthermore it looks like the parsing doesn't really work as when I place the point above a non-c primitive type (i.e. not int,double,float, etc) instead of printing the type's definition in the modeline an error message like
Idle Service Error semantic-idle-local-symbol-highlight-idle-function: "#<buffer DEPFETResolutionAnalysis.cc> - Wrong type argument: stringp, (((0) \"IndexMap\"))"
Idle Service Error semantic-idle-summary-idle-function: "#<buffer DEPFETResolutionAnalysis.cc> - Wrong type argument: stringp, ((\"fXBetween\" 0 nil nil))"
where DEPFETResolutionAnalysis.cc is the file & buffer I'm currently editing and IndexMap and fXBetween are types defined in files included by the file I'm editing/some file included by the file I'm editing.
I have not tested any further features of CEDET/semantic as the problem is pretty annoying. My cedet config can be found here.
EDIT: With the help of Alex Ott I kinda solved the first problem. It was due to my horrible cedet initialisation. See his first answer for the proper way to configure CEDET!
There still remains the problem with the Idle Service Error (which, when enabling global-semantic-idle-local-symbol-highlight-mode, occurs permanently, not only when checking the definition of the type at point).
And there is the new problem of how to disable the site-wise init file(s).
EDIT2: I have executed semantic-debug-idle-function in a buffer where the problem occurs and it produces a ~700kb [sic!] output. It looks like it is performing some operations on a data container which, by the looks of it, contains information on all the symbols defined in the files parsed. As I have parsed a rather large package (~20Mb source files) this table is rather large. Can semantic handle a database that large or is this impossible and the reason of my problem?
EDIT3: Deleting the content of ~/.semanticdb and reparsing all includes did the trick. I still need to disable the site-wise init files but as this is not related to CEDET I will close this question (the question related to the site-wise init files can be found here).
You need to change your init file so it will perform loading of CEDET only once, not in the hook that will be called for each .h/.hpp/.c/.cpp files. You can change this config as the base, and read more in following article.
The problem that you have is caused because Semantic is trying to analyze header files, and when it tries to open them, then its initialization routines are called again, and again...
The first problem was solved by correctly configuring CEDET which is discribed on Alex Ott's homepage. His answer solves this first problem. The config file specified in his answer is a great start for a nice config; I have used the very same to config CEDET for my needs.
The second problem vanished once I updated CEDET from 1.1 to the bazaar (repository) version, which is explained here and in Alex' article. Additionaly one must delete the content of the directory ~/.semanticdb (which contains the semantic database and was corrupted I guess).
I'd like to thank Alex Ott for his help and sticking with me throughout my journey to the solution :)
I am using C++ on Netbeans 7.1 on Ubuntu 11.04. For some reason, the following code results in the error message "Unable to resolve identifier cout".
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello,world!\n";
return 0;
}
Any help resolving this problem would be greatly appreciated.
The solution for your problem is at least strange ;)
Once iostream header is added, one has to reparse code. Click right on a project, go to code assistance and click to reparse project. Worked for me.
I was using netbeans for mac.
check whether iostream is really getting included;
i have tried your code on my machine using eclipse cdt it worked fine.so, please check the
includes.
What sort of file is this in? Is it a .h file, or .hpp file? I had this same issue. Netbeans can be ridiculous sometimes with C++. For me, I changed #include <iostream> to #include<iostream.h>
This may seem too simple, but...
In my NetBeans installation, when I go to create a new project, specify C/C++, it brings up a dialog box prompting for "Project Name:", location, folder, makefile name, and then...
a check box for "Create Main File", an edit box with "main" filled in, and to the right of that is a drop down list that reads "C". If you hit Finish, this will create "main.c" (C, but NOT a C++ file). Instead, in the drop down list, select "C++". Then the IDE creates main.cpp, which will be compiled with g++ and will find those includes and functions.
There is a difference between std::cout and cout. You don't currently have std::cout defined in your file. std::cout is a c standard out. In C++ we only need cout to work with iostream.
If you must use a standard c out then do the following:
Add this to the top under iostream
#include <iostream> //Input output stream in C++
#include <cstdlib> //Stands for c standard library
using namespace std;
Your code will now work because:
This change defines std::cout and std::cin among other things. (standard in, standard out respectively.)
However, I'd recommend this alternative if you don't need standard in outs:
Replace std::cout with cout, because cout is defined in iostream in C++. Your program would have worked without the std:: portion of your cin cout commands because you originally included iostream.
Try taking out the using namespace std; - it's generally considered bad form anyway :-)
I'm not sure that will fix the problem but most people either use the namespace or fully qualify things like std::cout. I've never seen code that does both.
The other thing to check is that the iostream header actually is being bought in. In other words, are there any errors on that line. A lot of problems (at least in the Windows world, so it may not necessarily apply to you) seem to be due to faulty path setup in NetBeans.
Hey look at your Output Debug. You may see "no permission". After I changed the file permission of "/YourProjekt/dist/Debug/GNU-Linux/file" to runable and everyone can read and write the error disappeared. (BTW: I had the bug because I was on a NTFS System with my Projekt, it have to be ext partition)
Hope I can help you with that.
Try taking out the std:: next to cout