#1 Le 13/11/2007, à 17:10
- _JFK_
Problème de compilation de la librairie htmlcxx
Bonjour à tous,
j'essai d'utiliser la librairie http://htmlcxx.sourceforge.net/ qui permet par exemple d'extraire des urls d'une page web. J'ai compilé la librairie dans un endroit précis pour ne pas casser ma ubuntu et en mettre partout. Mon but étant surtout de lier cette librairie de manière statique au programme.
J'essai de compiler l'exemple de base, celui sur la page d'accueil du projet, j'ai juste ajouté un #include <string> et #include <iostream>. voilà donc le code :
#include <htmlcxx/html/ParserDom.h>
#include <iostream> // pour std::cout
#include <string> // pour std::string
using namespace std;
//Parse some html code
string html = "<html><body>hey</body></html>";
HTML::ParserDom parser;
tree<HTML::Node> dom = parser.parseTree(html);
//Print whole DOM tree
cout << dom << endl;
//Dump all links in the tree
tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
if (it->tagName() == "A")
{
it->parseAttributes();
cout << it->attributes("href");
}
}
//Dump all text of the document
it = dom.begin();
end = dom.end();
for (; it != end; ++it)
{
if ((!it->isTag()) && (!it->isComment()))
{
cout << it->text();
}
}
et voilà mon essai de compilation :
$ g++ -o test_htmlcxx test_htmlcxx.cpp -lhtmlcxx -I/home/touns/developpement/essai_htmlcxx/lib_htmlcxx/include/ -L /home/touns/developpement/essai_htmlcxx/lib_htmlcxx/lib/
test_htmlcxx.cpp:10: erreur: «HTML" has not been declared
test_htmlcxx.cpp:10: erreur: expected constructor, destructor, or type conversion before «parser"
test_htmlcxx.cpp:11: erreur: «HTML" was not declared in this scope
test_htmlcxx.cpp:11: erreur: patron de l'argument 1 est invalide
test_htmlcxx.cpp:11: erreur: patron de l'argument 2 est invalide
test_htmlcxx.cpp:11: erreur: invalid type in declaration before «=" token
test_htmlcxx.cpp:11: erreur: «parser" was not declared in this scope
test_htmlcxx.cpp:14: erreur: expected constructor, destructor, or type conversion before «<<" token
test_htmlcxx.cpp:17: erreur: «HTML" was not declared in this scope
test_htmlcxx.cpp:17: erreur: patron de l'argument 1 est invalide
test_htmlcxx.cpp:17: erreur: patron de l'argument 2 est invalide
test_htmlcxx.cpp:17: erreur: expected initializer before «it"
test_htmlcxx.cpp:18: erreur: «HTML" was not declared in this scope
test_htmlcxx.cpp:18: erreur: patron de l'argument 1 est invalide
test_htmlcxx.cpp:18: erreur: patron de l'argument 2 est invalide
test_htmlcxx.cpp:18: erreur: expected initializer before «end"
test_htmlcxx.cpp:19: erreur: expected unqualified-id before «for"
test_htmlcxx.cpp:19: erreur: expected constructor, destructor, or type conversion before «!=" token
test_htmlcxx.cpp:19: erreur: expected unqualified-id before «++" token
test_htmlcxx.cpp:29: erreur: expected constructor, destructor, or type conversion before «=" token
test_htmlcxx.cpp:30: erreur: expected constructor, destructor, or type conversion before «=" token
test_htmlcxx.cpp:31: erreur: expected unqualified-id before «for"
test_htmlcxx.cpp:31: erreur: expected constructor, destructor, or type conversion before «!=" token
test_htmlcxx.cpp:31: erreur: expected unqualified-id before «++" token
Pourquoi est ce que j'obtiens ces erreurs svp? Je ne comprends pas ma chaine html est bien déclaré pourtant.
Merci d'y apporter votre éclairage!
#2 Le 13/11/2007, à 18:42
- Link31
Re : Problème de compilation de la librairie htmlcxx
using namespace htmlcxx;
Hors ligne
#3 Le 14/11/2007, à 11:53
- _JFK_
Re : Problème de compilation de la librairie htmlcxx
Merci! ça marche un peu mieux, il me reste ces erreurs encore :
test_htmlcxx.cpp:15: erreur: expected constructor, destructor, or type conversion before «<<" token
test_htmlcxx.cpp:20: erreur: expected unqualified-id before «for"
test_htmlcxx.cpp:20: erreur: expected constructor, destructor, or type conversion before «!=" token
test_htmlcxx.cpp:20: erreur: expected unqualified-id before «++" token
test_htmlcxx.cpp:30: erreur: expected constructor, destructor, or type conversion before «=" token
test_htmlcxx.cpp:31: erreur: expected constructor, destructor, or type conversion before «=" token
test_htmlcxx.cpp:32: erreur: expected unqualified-id before «for"
test_htmlcxx.cpp:32: erreur: expected constructor, destructor, or type conversion before «!=" token
test_htmlcxx.cpp:32: erreur: expected unqualified-id before «++" token
la ligne 15 étant mon cout :
#include <htmlcxx/html/ParserDom.h>
#include <iostream> // pour std::cout
#include <string> // pour std::string
using namespace std;
using namespace htmlcxx;
//Parse some html code
string html = "<html><body>hey</body></html>";
HTML::ParserDom parser;
tree<HTML::Node> dom = parser.parseTree(html);
//Print whole DOM tree
cout << dom << endl;
//Dump all links in the tree
tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
if (it->tagName() == "A")
{
it->parseAttributes();
cout << it->attributes("href");
}
}
//Dump all text of the document
it = dom.begin();
end = dom.end();
for (; it != end; ++it)
{
if ((!it->isTag()) && (!it->isComment()))
{
cout << it->text();
}
}
Je ne vois pas pourquoi j'aurai besoin d'un constructeur pour ma chaine pour mon cout, ça marche sans normalement.
Merci encore de m'éclairer.