compile rapidxml under linux with g++ - g++

The following simple program can't be compiled with gcc 4.4.3
#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
#include "rapidxml_iterators.hpp"
int main()
{
return 0;
}
Compile produces following errors:
rapidxml_iterators.hpp:21: error: expected nested-name-specifier
rapidxml_iterators.hpp:21: error: invalid declarator before ‘value_type’
rapidxml_iterators.hpp:22: error: expected nested-name-specifier
rapidxml_iterators.hpp:22: error: invalid declarator before ‘&’ token
..........
What I am doing wrong?

These errors are caused by the rapidxml_iterators.hpp header. It seems including this header is not necessary for regular xml parsing. Apparently, the iterators defined in there are not really usable anyway. It might be something still under development. See also here.

The rapidxml_iterators.hpp have some problem with it. You have to change it to this:
typedef xml_node<Ch> value_type;
typedef xml_node<Ch> &reference;
typedef xml_node<Ch> *pointer;
typedef typename std::ptrdiff_t difference_type;
typedef typename std::bidirectional_iterator_tag iterator_category;

Simple solution for simple case
You don't actually need rapidxml_iterators.hpp but were doing a sanity check, right ?
Solution: only #include the headers you actually need.
It's a general rule. #include'ing everything is like eating too much : it turns the situation fat and slow.
By contrast, including only what you need:
keeps you aware of your actual code dependency,
helps keeping you safe from namespace pollution and the occasional name clashes and sometimes even portability issues,
alerts you when you are starting to mess together things that should be kept separated.
If you really need rapidxml_iterators.hpp
At this point, the problem is probably solved. If you really need rapidxml_iterators.hpp, it's indeed buggy (looks like this particular error is a Microsoftism). This problem and others were reported on February 2010 on http://sourceforge.net/p/rapidxml/bugs/10/ with suggested solutions different from #user437634's, still open and present in current release as of July 2013.

Related

Clion IDE, Whenever i create new file gives error [duplicate]

In the journey to learning C++ im learning through the C++ Manual thats on the actual website. Im using DevC++ and have hit a problem, not knowing whether its the compilers error or not.
I was going through this code bit by bit typing it in myself, as I feel its more productive, and adding my own stuff that ive learnt to the examples, then I get to initialising variables. This is the code that is in the C++ manual
#include <iostream>
using namespace std;
int main ()
{
int a=5; // initial value = 5
int b(2); // initial value = 2
int result; // initial value undetermined
a = a + 3;
result = a - b;
cout << result;
return 0;
}
This is popping up a compiler error saying " Multiple definitions of "Main""
Now This is on the actual C++ page so im guessing its a compiler error.
Could someone please point me in the right direction as to why this is happening and what is the cause for this error.
Multiple definitions of "main" suggests that you have another definition of main. Perhaps in another .c or .cpp file in your project. You can only have one function with the same name and signature (parameter types). Also, main is very special so you can only have one main function that can be used as the entry point (has either no parameters, one int, or an int and a char**) in your project.
P.S. Technically this is a linker error. It's a subtle difference, but basically it's complaining that the linker can't determine which function should be the entry point, because there's more than one definition with the same name.
Found I had two file references in my tasks.json file that were causing this error and which took me a long time to figure out. Hope this helps someone else..... See "HERE*****" below:
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
//"${file}", //HERE**********************
"-lgtk-3",
"-lgdk-3",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-latk-1.0",
"-lcairo-gobject",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-o",
"${fileDirname}/${fileBasenameNoExtension}" //HERE*************
],
When I practiced CMake, I encountered the same problem. Finally, I found that the source code path set in the cmakelist project was incorrect. As a result, the compiled files included many duplicate files generated during CMake execution. As a result, compilation errors occurred

New error in VS 2019, but there is no error? C++

I have been working on a project for a while now, with many stable builds sent out etc.
Today however, I encountered 3 errors in one line of code (in a page of code that is only 17 lines long), that has been working perfectly fine for over a year now.
I'll show the "broken code" below.
The only problem is, there is no error. No red underlines or any actual problem, nothing has been changed, or anything I can think of. I made one minor edit today to the project that was entirely unrelated to that specific code, apart from calling one of two functions inside of it. The called function isn't even the function that is breaking.
Worst of all, a project backup that is almost identical compiles no problems. Again, it's only that 1 minor edit unrelated that is different.
Visual studio error list shows me three errors;
Error C3083 'chrono': the symbol to the left of a '::' must be a type
Error C2039 'time_point': is not a member of 'std'
Error C2061 syntax error: identifier 'time_point'
Here is the offending code.
#ifndef _INPUT_HPP
#define _INPUT_HPP
#include "../Structure/Struct.hpp"
namespace Input
{
bool IsPressed(int virtual_key);
namespace Mouse
{
void Lerp(Vector2 pos, double animation, double repeat_delay, std::chrono::time_point<std::chrono::steady_clock> f_excess);
}
}
#endif
All errors come from line 12 - starting with: void lerp
You don't #include <chrono>, so of course the compiler does not know the symbols.
You might have been including it indirectly and stopped because you removed some other #include directive somewhere else. Don't rely on indirect #includes—you are using it here, you should have #include <chrono> here. See include-what-you-use.

Casting Qt5 QHelpEngine need obsolete casting

I am attempting to install a help browser starting from
http://www.walletfox.com/course/qhelpengineexample.php
For the line
tWidget->addTab(helpEngine->contentWidget(), tr("Contents"));
I receive error message
no known conversion from QHelpIndexWidget* to QWidget*
and really, if I make explicite casting with
tWidget->addTab((QWidget*)helpEngine->contentWidget(), tr("Contents"));
the program compiles and runs fine. What is going on here?
Most likely you forgot to #include <QHelpIndexWidget>.
Then the compiler can't deduct that a QHelpIndexWidget inherits from QWidget.
If you would try to access the QHelpIndexWidget*, like e.g.
qDebug() << helpEngine->indexWidget()->objectName();
without the include, you would get the better compiler error "QHelpIndexWidget is of incomplete type" or similar, which means that the type is forward declared, but the complete declaration is not accessible.
Additionally, I would suggest avoiding c-style casts and use static_cast<TYPE>(var) instead.

How to identify a warning type in a gcc compile log to disable it?

I have many warnings when I compile my project under Eclipse CDT Indigo and g++ (Debian 4.9.2-10) 4.9.2. From here, it may be explained by some Eclipse parser bugs, plus possibly some external library bugs.
I will upgrade Eclipse of course, but I cannot now.
I would like then to suppress these cumbersome warnings. I read the manual here, but still I don't see how to identify which options to set. I have unchecked the -Wall option in Eclipse, but nothing is changed. All Eclipse warnings are disabled now.
Here is a pastbin of my compile log.
It looks like something ate your actual warning lines. All gcc warnings have the word "warning" in at least one of the lines.
EDIT Some builds of gcc actually produce similar messages ("note" lines, "required from" lines, "instantiated from" lines... but no actual "error" or "warning" line). It looks like there's a bug in gcc. — end edit.
Out of all gcc warnings, I know of only one that is related to overloading and has "note" submessages that lists candidate functions. The warning reads
C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second
and it cannot be turned off. If you see such warning, your program is non-compliant and you should fix it.
Here's an example of such non-compliant code. with function signatures matching yours:
#include <string>
struct KeyWord
{
KeyWord(const std::string&);
operator std::string&() const;
};
struct A
{
bool operator() (const std::string&, const std::string&) const;
bool operator() (const KeyWord&, const KeyWord&);
};
int main ()
{
A a;
std::string s;
const std::string r;
a(s, r);
}
Making the second operator() const solves the problem.

#include <malloc.h> -- Xcode

I have an interesting problem where I can't include malloc.h in my project.
I need malloc.h for Paul Nettle's mmgr tool (I'm not keen on using instruments)
Problem is I can't find the system library for memalign.
Xcode keeps failing because it cannot this definition & neither can I.
Anyone else seen this?!
If you just need to use malloc then you can grab it from the stdlib like so:
#include <stdlib.h>
Otherwise, you can directly call malloc.h like so:
#include <malloc/malloc.h>
EDIT:
A posix_memalign() exists in stdlib.h. The implementation looks like:
int posix_memalign(void **, size_t, size_t);
Perhaps you can make an alias to this and use it?