Compilation error after including jsoncpp - c++

When I try to build test sources I get an error like after this.
stl_tree.h:542:14: error: ‘__node’ does not name a type
::new(__node) _Rb_tree_node<_Val>;
Executor's content.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
int main(int argc, char** argv) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(argc, argv);
}
My test' s source code starts with below includes.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
#include <iostream>
#include "common/data_util_astro_cfg.h"
TEST_GROUP(ASTRO_UTIL_TEST) {
void setup() { }
void teardown() { }
};
And the "common/data_util_astro_cfg.h" file has following includes.
#include "../data/data_type_file.h"
#include <json/json.h>
static AstroConfigs toAstroConfigs(std::string content)
My problem is I get compilation error with these includes, when I remove line json.h include everything is fine I can get binary output.
I think the problem is about new operator' s conflict. The solution is offered by Cpputest side and it is located on http://cpputest.github.io/manual.html#memory_leak_detection. But it isn't clear somehow. :(
The question has been already defined on Compilation error after including <map>. It is so similar to mine but the problem has solved with creating new project. In that case I have no option for that. I'm using Yocto project and the project has created with auto generation tools as well.
Can you help me on this? (Thank you for your time.)

Unfortunately, I solved the problem after a while. It seems something wrong with CPPUTest. At the top of the test file, I have several includes. Some of them belong to CPPUTest library, some of them are mine. My includes are following CPPUTest that's why I’m getting an error. If I changed their places, it would be working correctly. It seems meaningless, but it is the correct solution. ”PROBLEM SHOULD BE RESOLVED WITH DEFINE CPPUTEST LIBRARIES AT THE BOTTOM OF YOUR INCLUDE LIST.”

Related

Getting Started with ANTLR4 and C++

First time question asker here, so bear with me. So I've got a grammar file from the grammars repository that I'm trying to use with C++. (Developing on macOS). I have no issue generating the lexer and parser using ANTLR. But after that, I have no idea how to run/use the resulting .cpp and .h files. I understand that there is an antlr runtime that I must download, and I have done so from the antlr.org website (gives me two folders, antlr4-runtime and lib), but my novice understanding of C++ seems to be preventing me from getting any further than that. How do I use the runtime to work with these files? I'm not using an IDE, just g++ from the command line. Thank you for any help!
I found this guide helpful: Getting Started with ANTLR in C++. (Ah, saw #ggorlen's comment after.)
If you scroll down on that page to a little past halfway, there's a section titled How to Use ANTLR in C++. I think that's where you are.
I'll copy that example over as SO generally prefers this. Say this is your main.cpp:
#include <iostream>
#include "antlr4-runtime/antlr4-runtime.h"
#include "antlr4-runtime/SceneLexer.h"
#include "antlr4-runtime/SceneParser.h"
#include "ImageVisitor.h"
using namespace std;
using namespace antlr4;
int main(int argc, const char* argv[]) {
std::ifstream stream;
stream.open("input.scene");
ANTLRInputStream input(stream);
SceneLexer lexer(&input);
CommonTokenStream tokens(&lexer);
SceneParser parser(&tokens);
SceneParser::FileContext* tree = parser.file();
ImageVisitor visitor;
Scene scene = visitor.visitFile(tree);
scene.draw();
return 0;
}
You want to include your lexer and parser .h (header) files instead of the SceneLexer/Parser in the example, and also include antlr4-runtime.h. Then run g++ on all your .cpp files, e.g.
$ g++ main.cpp YourLexer.h YourParser.h

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

Can't use C library (function)

The following is my environment:
Eclipse IDE for C/C++ Developers(Juno)
Qt 4.8.3
Qt Eclipse Integration v1.6.1
mingw(20120426)
When I create a Qt console project, I just can't use C library functions, such as exit(int) or atoi(string).
The error message is such like Function 'exit' could not be resolved.
I have included stdlib.h, but still can't work.
I don't know if there is some relation with index.
20121109 Update
Thanks for give me help!
atoi is just a example!
Although I write program in c++, but sometimes I want use C library, so I tag it c++.
The following is what I include
C:/MinGW/include
C:/MinGW/lib/gcc/mingw32/4.6.2/include
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++/backward
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++/mingw32
C:/MinGW/lib/gcc/mingw32/4.6.2/include-fixed
Others are Qt library.
And the following is main.
#include <QtCore>
#include <QCoreApplication>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
std::exit(0);
QCoreApplication a(argc, argv);
return a.exec();
}
I try this way but still get error message Function 'exit' could not be resolved.
Thanks a lot!
First of all, use C++ headers style. For stdlib.h :
#include <cstdlib>
Then, I guess you're not bringing namespace information. Either write :
using namespace std;
(even if I don't recommend it) or
using std::exit using std::atoi;
or use fully qualified names :
std::exit(-1);
Finally, why do you need such functions like atoi ?
I had a similar case which I was able to solve by moving #include <cstdlib> to the top of the list of header includes. This means that one of the other header files had a dependency on something in the cstdlib. This is not really good practice but they're all system header files and trying to correct them would make the code less portable between similar development systems.
I use Eclipse C++ Kepler. This is what I did and it worked for me:
right-click in editor's screen>Run As>Local C/C++ Application.

Unexpected end of a file

When trying in VS2010 Ultimate sp1 to #include ANY std header inside "stdafx.h" I'm getting an error:
fatal error C1004: unexpected end-of-file found
Does anyone else experience this or is there something wrong with my installation?
Edit
My main looks like this:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
stdafx.h looks like this:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#include <_dbdao.h>//if I remove this line it will compile
stdafx.cpp looks like this:
#include "stdafx.h"
AND THERE IS NOTHING MORE
There are a few reasons why the Visual Studio Compiler gives this error. MSDN explains it here
The compiler reached the end of a source file without resolving a
construct. The code may be missing one of the following elements:
A closing brace
A closing parenthesis
A closing comment marker (*/)
A semicolon
My guess is that it's not really related to the stdafx.h file, but rather you have a class somewhere like this:
class A {
...
}
without the semicolon after }. It has to be
class A {
...
};
If this does not solve it you should do what tenfour is suggesting. Eliminate until it compiles to find out what causes it.
If you use precompiled headers, you need to include stdafx.h in every source file in your project.
Otherwise it can lead to the error message you quoted here.
(This answer is based on the given information)

Errors thrown from stl when compiling a module which uses the "Meschach" library

I'm working on a module which uses a shared library, which in turn has a static library linked to it. The shared library build works fine and generates a .so. When I try to use it in the module, I get a variety of errors, most of which are based on stl (stl collections to be specific), at the compilation stage. The errors look like:
In file included from /usr/include/c++/4.3/list:68,
from /home/gayan/LHIMo/LHI/src/CalcEngine/include/JuncNodeInfo.h:11,
from /home/gayan/LHIMo/LHI/src/CalcEngine/include/RiverFlowParameter.h:11,
from Main.cpp:11:
/usr/include/c++/4.3/bits/stl_list.h:465:11: error: macro "catch" requires 3 arguments, but only 1 given
This is given in most places which use list, vector or map.
Please help me to resolve this.
Sample code: "CalcEngine.h" in the library:
#ifndef LHI_CALCENGINE_H_
#define LHI_CALCENGINE_H_
extern "C"{
#include <matrix2.h>
}
class CalcEngine{
public:
protected:
};
#endif /* LHI_CALCENGINE_H_ */
Main.cpp in the application:
#include <iostream>
#include <CalcEngine.h>
#include <list> // The compilation fails as soon as this is added
int main(int argc, char** argv){
return -1;
}
I feel this has something to do with the matrix2.h file but could not pinpoint it. The file could be found here
Doing some googling it seems like the Meschach library has a macro called catch (defined err.h indirectly included by matrix2.h) causing c++ code having exception catching to fail.
Try
#undef catch
after you are done including the meschach headers and see if works better.