DOMElement has no member named 'getFirstElementChild xercesc C++ - c++

I'm writing a xml parser file, called GetConfig.cpp.
Here is my header file of 'GetConfig.h`:
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMText.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
However, When I try to compile the program, I get:
/home/pribeiro/sandbox/GetConfig.cpp:372: error: 'class xercesc_2_2::DOMElement' has no member named 'getFirstElementChild'
/home/pribeiro/sandbox/GetConfig.cpp:381: error: 'class xercesc_2_2::DOMElement' has no member named 'getFirstElementChild'
/home/pribeiro/sandbox/GetConfig.cpp:392: error: 'class xercesc_2_2::DOMElement' has no member named 'getFirstElementChild'
/home/pribeiro/sandbox/GetConfig.cpp:396: error: 'class xercesc_2_2::DOMElement' has no member named 'getNextElementSibling'
I'm not sure why I'm getting that ...
In that declaration I use:
DOMElement *volume = dynamic_cast<xercesc::DOMElement*>
(volManager);
while(volume){
// to the parsing here
volume = volume->getNextElementSibling();
}
I'm not sure ... Maybe something related to the version of xercesc? When I compiled that for xercesc 3.1 it worked fine.

Those functions were introduced in Xerces 3
You see them mentioned in the Xerces 3 API documentation:
http://xerces.apache.org/xerces-c/apiDocs-3/classDOMElement.html
but not in the Xerces 2 API documentation:
http://xerces.apache.org/xerces-c/apiDocs-2/classDOMElement.html
The string "getFirstElementChild" occurs 31 times in the Xerces 3.1.1 sources but not at all in the Xerces 2.8.0 sources:
erik#ubuntu:/tmp$ file=http://archive.apache.org/dist/xerces/c/2/sources/xerces-c-src_2_8_0.tar.gz
erik#ubuntu:/tmp$ curl -s $file | tar xfz - -O | grep getFirstElementChild | wc -l
0
erik#ubuntu:/tmp$ file=http://archive.apache.org/dist/xerces/c/3/sources/xerces-c-3.1.1.tar.gz
erik#ubuntu:/tmp$ curl -s $file | tar xfz - -O | grep getFirstElementChild | wc -l
31
erik#ubuntu:/tmp$

Related

Tesseract api linker (or build?) problem on window

I want to use tesseract api on my project. And the problem is I can't compile my test code that look like this.
#include <iostream>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
int main()
{
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->End();
delete api;
return 0;
}
I'm using this
g++ -L/Projects/cpp/CPE1/Project/lib/ -ltesseract50 -lleptonica -I/Projects/cpp/CPE1/Project/include t.cpp -o t
and got
C:\Users\MSINOT~1\AppData\Local\Temp\cc4xWMfF.o:t.cpp:(.text+0x21): undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'
C:\Users\MSINOT~1\AppData\Local\Temp\cc4xWMfF.o:t.cpp:(.text+0x44): undefined reference to `tesseract::TessBaseAPI::End()'
collect2.exe: error: ld returned 1 exit status
my folder structure looks like this (this is all on drive D:)
\---Project
+---bin
+---cmake
+---include
| +---leptonica
| \---tesseract
+---leptonica-1.80.0
+---lib
| +---cmake
| \---pkgconfig
+---tesseract-master
\---Uics
[my code is here]
I compiled leptonica and tesseract following this https://tesseract-ocr.github.io/tessdoc/Compiling.html#windows on "Develop Tesseract" and specify install path to my project folder.
I'm a noob in this type of problem, so if you have completely different ways to use tesseract API pls tell me.
g++.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Tesseract from main branch https://github.com/tesseract-ocr/tesseract
Leptonica from 1.80.0 release
https://github.com/DanBloomberg/leptonica
cmake version 3.19.4
*edit add lib folder listing
D:\PROJECTS\CPP\CPE1\PROJECT\LIB
| leptonica.lib
| tesseract50.lib
|
+---cmake
| +---leptonica
| | LeptonicaConfig-version.cmake
| | LeptonicaConfig.cmake
| | LeptonicaTargets-release.cmake
| | LeptonicaTargets.cmake
| |
| \---tesseract
| TesseractConfig.cmake
| TesseractConfigVersion.cmake
| TesseractTargets-release.cmake
| TesseractTargets.cmake
|
\---pkgconfig
lept.pc
tesseract.pc

I am trying to build a simple program to read information from a mysql database

I want to write a command-line tool that will allow me to enter in commands and a variable and then the tool will return information sourced from a SQL database
I have created a project in Xcode, Installed mysql-connector-c++ and boost using homebrew but whenever I try to include the headers it will not allow me to compile, I have even tried using the exact path
#include <iostream>
#include "boost/shared_ptr.hpp"
#include "boost/smart_ptr/shared_ptr.hpp"
#include "/usr/local/mysql-connector-c++/include/jdbc/mysql_connection.h"
#include "/usr/local/mysql-connector-c++/include/jdbc/mysql_driver.h"
#include "/usr/local/mysql-connector-c++/include/jdbc/mysql_error.h"
I am not sure what I am doing wrong
a simple program i suggest using php ; i'm not sure about c++ but the language could be similar ;
save a example.php file :
<?php
error_reporting(~E_WARNING);
date_default_timezone_set('Asia/Taiwan');
// include files for required variables ;
$mysqli = new mysqli($Host, $User, $Password, $CustomerDB);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$arrayReceive = array();
if (!isset($_SESSION)){session_start();}
$sql = "select * from $DB.customeritem where Status='ACTIVE'";
$res = $mysqli->query($sql);
if (!$res){echo "Failed query Line18customeritem: (".$mysqli->errno.") ". $mysqli->error;}
echo "No. of customeritems : ".$res->num_rows."\r\n";
while($row=$res->fetch_assoc()){
// code to handle each row return from mysql query ;
}//end while
$_SESSION["customeritemArray"] = $customeritemArray;
// $mysqli->close();
?>
then command-line tool can enter :
php -f C:\wamp64\www\projectFolder\example.php
or you could make it a script.
I've seen in the mysql connector docs that the includes goes right that:
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/*.h>
Look that there are no "" it is <>

Using #define to include a file in C++/g++

I am not trying to write:
#include MACRO(arg)
instead, I am trying to write just:
MACRO(arg)
Many people say that we cant write such macro to #include any file, but those try fails on preprocessing stage only, below one passes preprocessor but fails later, I think.
I wrote following test code tmp1.cpp (which does not compile):
#define HASH #
#define ZX(arg) HASH include <arg>
ZX(iostream)
int main()
{
}
And below is the output of some commands:
$ g++ -E tmp1.cpp
# 1 "tmp1.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "tmp1.cpp"
# include <iostream>
int main()
{
}
$ g++ -E tmp1.cpp > tmp2.cpp
$ g++ tmp2.cpp
$ ./a.out
$ g++ tmp1.cpp
tmp1.cpp:1:14: error: stray ‘#’ in program
#define HASH #
^
tmp1.cpp:2:17: note: in expansion of macro ‘HASH’
#define ZX(arg) HASH include <arg>
^
tmp1.cpp:4:1: note: in expansion of macro ‘ZX’
ZX(iostream)
^
tmp1.cpp:2:22: error: ‘include’ does not name a type
#define ZX(arg) HASH include <arg>
^
tmp1.cpp:4:1: note: in expansion of macro ‘ZX’
ZX(iostream)
^
$
I wonder why tmp2.cpp compiles and executes successfully but tmp1.cpp fails on compilation stage ? Isn't it that first the preprocessor is run then its output is fed to compiler ? tmp2.cpp is just preprocessed version of tmp1.cpp only.
[EDIT]
I had requirement of:
#ifdef SOMETHING
#define ZX(arg)
#else
#define HASH #
#define ZX(arg) HASH include <arg>
#endif
[cpp.rescan]/3 The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one...
I believe your quest is hopeless.

Sierra, cpp command throwing 'iostream' file not found

I'm following a tutorial on my macbook pro with Sierra and Xcode9.0.1
I compiled the following hello world code with g++ without problems.
#include <iostream>
main() {
using namespace std;
cout << "Hello, World!" << endl;
}
But when I execute
cpp hello.cxx | more
as required by the tutorial, I got the following error message:
hello.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
# 1 "hello.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 330 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "hello.cpp" 2
Since you have a working g++ compiler, you may use the following command line for getting the preprocessed output:
g++ -E hello.cxx | more
The -E option instructs the compiler driver to execute the preprocessor and emit the preprocessed output.

Simple C++ write-to-file not working within Mac OS X App - why? (and why me?)

The code is simple enough:
#include <iostream>
#include <fstream>
#include <string>
int main(int argc, char* argv[] )
{
std::ofstream theStream;
theStream.open("trash.txt");
theStream << "some words" << std::endl;
theStream.close();
}
If I run it from the command line then I get the expected file in the same directory. If a package the contents of the executable within a MacOS .app, then no file is written anywhere. (Or perhaps it is just promptly erased?)
Here's the simple script I'm using to place the executable into the .app. Perhaps that is where I'm going wrong.
#!/bin/bash
appName=MyApp
if [ $1 ]
then
appName=$1
else
echo "usage: convertToApp executableFile"
exit
fi
if [ -e "$appName" ]
then
mkdir $appName.app
mkdir $appName.app/Contents
mkdir $appName.app/Contents/MacOS
mkdir $appName.app/Contents/Resources
cp $appName $appName.app/Contents/MacOS/$appName
echo -n 'APPL????' > $appName.app/Contents/PkgInfo
else
echo "specified file does not exist"
fi
Any idea why I can't see the file I want to see?
Instead of "trash.txt", try to use the full path or change the current working directory.