Le problème de compilation XmppPump de libjingle
-
10-10-2019 - |
Question
Je viens de commencer à coder un robot de chat Gtalk en utilisant libjingle. Je vais avoir un problème obtenir le compilateur de trouver la classe XmppClient appelée par classe XmppPump. Le XmppClient est fourni par libjingle dans le fichier de conversation / XMPP / xmppclient.h, mais pour une raison quelconque, il ne fonctionne pas pour moi et il m'a été frustrant ces derniers temps. Nous espérons que vous les gars serez en mesure de me aider!
J'utilise libjingle-0.5.1 et mon g ++ version compilateur est 4.4.5. Mon OS est Ubuntu 10.10, 32 bits.
Voici comment je suis en train de compiler mon code:
g++ -g -Werror -DPOSIX -DEXPAT_RELATIVE_PATH -DFEATURE_ENABLE_SSL -DHAVE_OPENSSL_SSL_H=1 -I../include -I../misc/libjingle-0.5.1 -I../misc/libjingle-0.5.1/talk/third_party/expat-2.0.1 -I../misc/libjingle-0.5.1/talk/third_party/srtp/include -L../lib -lpthread -lssl -o ../bin/gtalk_bot.bin ../obj/main.o /usr/local/lib/libglog.a ../misc/libjingle-0.5.1/talk/build/dbg/lib/libjingle.a ../misc/libjingle-0.5.1/talk/build/dbg/lib/libexpat.a ../misc/libjingle-0.5.1/talk/build/dbg/lib/libsrtp.a ../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a
Voici le message d'erreur:
../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a(xmpppump.o): In function `XmppPump::XmppPump(XmppPumpNotify*)': xmpppump.cc:(.text._ZN8XmppPumpC2EP14XmppPumpNotify+0x6e): undefined reference to `buzz::XmppClient::XmppClient(talk_base::TaskParent*)' ../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a(xmpppump.o): In function `XmppPump::XmppPump(XmppPumpNotify*)': xmpppump.cc:(.text._ZN8XmppPumpC1EP14XmppPumpNotify+0x6e): undefined reference to `buzz::XmppClient::XmppClient(talk_base::TaskParent*)' ../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a(xmpppump.o): In function `XmppPump::DoLogin(buzz::XmppClientSettings const&, buzz::AsyncSocket*, buzz::PreXmppAuth*)': xmpppump.cc:(.text._ZN8XmppPump7DoLoginERKN4buzz18XmppClientSettingsEPNS0_11AsyncSocketEPNS0_11PreXmppAuthE+0xa9): undefined reference to `buzz::XmppClient::Connect(buzz::XmppClientSettings const&, std::basic_string, std::allocator > const&, buzz::AsyncSocket*, buzz::PreXmppAuth*)' ../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a(xmpppump.o): In function `XmppPump::DoDisconnect()': xmpppump.cc:(.text._ZN8XmppPump12DoDisconnectEv+0x25): undefined reference to `buzz::XmppClient::Disconnect()' ../misc/libjingle-0.5.1/talk/build/dbg/lib/libxmpphelp.a(xmpppump.o): In function `XmppPump::SendStanza(buzz::XmlElement const*)': xmpppump.cc:(.text._ZN8XmppPump10SendStanzaEPKN4buzz10XmlElementE+0x2c): undefined reference to `buzz::XmppClient::SendStanza(buzz::XmlElement const*)' collect2: ld returned 1 exit status make: *** [../bin/gtalk_bot.bin] Error 1
Et voici mon code:
#include <string>
#include <iostream>
#include <assert.h>
#include <getopt.h>
#include "glog/logging.h"
#include "talk/base/thread.h"
#include "talk/base/physicalsocketserver.h"
#include "talk/base/socketaddress.h"
#include "talk/base/cryptstring.h"
#include "talk/base/ssladapter.h"
#include "talk/xmpp/jid.h"
#include "talk/xmpp/xmppclient.h"
#include "talk/xmpp/xmppclientsettings.h"
#include "talk/examples/login/xmpppump.h"
#include "talk/examples/login/xmppauth.h"
#include "talk/examples/login/xmppthread.h"
using namespace std;
int readCommandLineArguments(int argc, char **argv);
int getUserName(string *username);
int getPassword(string *password);
buzz::Jid serverJid;
string username;
string password;
string auth_cookie;
int main(int argc, char **argv){
int status = 0;
// use: GLOG_log_dir="log" ./gtalk_bot.bin
google::InitGoogleLogging(argv[0]);
talk_base::PhysicalSocketServer pss;
talk_base::AutoThread main_thread(&pss);
// Get the information we'll need to sign in
buzz::Jid jid;
talk_base::InsecureCryptStringImpl pass;
buzz::XmppClientSettings xcs;
XmppPump pump;
//XmppHandler xhandler;
status = readCommandLineArguments(argc, argv);
if(username.empty()){
// get the user name if there's none in the command line argument
status = getUserName(&username);
}
jid = buzz::Jid(username);
assert(jid.IsValid() || jid.node() != "");
if(!username.empty() && password.empty()){
// If username is provided, but the password isn't, ask for one.
status = getPassword(&password);
}
pass.password() = password;
// Turn on SSL
talk_base::InitializeSSL();
xcs.set_user(jid.node());
xcs.set_resource("one_chat_bot"); //TODO: need to investigate what this is
xcs.set_host(jid.domain());
xcs.set_use_tls(true);
xcs.set_pass(talk_base::CryptString(pass));
xcs.set_server(talk_base::SocketAddress("talk.google.com", 5222));
//xhandler.DoLogin(xcs, new XmppSocket(true), NULL);
// xhandler.DoLogin(xcs, new XmppSocket(true), NULL);
main_thread.Run();
// xhandler.DoDisconnect();
//delete objects here
return 0;
}
int readCommandLineArguments(int argc, char **argv){
int input = 0;
int rc = 0;
int options_index = 0;
static struct option long_options[] = {
{"username", required_argument, 0, 'u'},
{"password", required_argument, 0, 'p'},
{0, 0, 0, 0}
};
while((input = getopt_long(argc, argv, "u:p:", long_options, &options_index)) != -1 && rc == 0){
switch(input){
case 'u':
if(optarg){
username = optarg;
}
break;
case 'p':
if(optarg){
password = optarg;
}
break;
case '?':
default:
rc = 1;
break;
}
}
return rc;
}
int getUserName(string *username){
int rc = 0;
cout << "google username: ";
cin >> *username;
return rc;
}
int getPassword(string *password){
int rc = 0;
cout << "password: ";
cin >> *password;
return rc;
}
Voici ma structure de répertoire. Il y a trois dossiers libjingle parce que je faisais des expériences et essayer différentes choses pour voir si je peux résoudre le problème de compilation. Les dossiers libjingle ne changent pas, sauf que expat-2.0.1 / et SRTP / dossiers sont copiés dans le libjingle / talk / third_party / dossier. La structure libjingle-0.5.1 / est à peu près la même chose que le tronc svn situé ici:
http://code.google.com/p/libjingle / source / browse / tronc / # tronc
Sauf que mon dossier libjingle-0.5.1 est déjà compilé.
gtalk_bot$ ls * bin: log include: lib: misc: expat-2.0.1 glog-0.3.1.tar.gz libjingle-0.4.0.tar.gz libjingle-0.5.1 libjingle-0.5.tar.gz srtp swtoolkit expat-2.0.1.tar.gz libjingle-0.4.0 libjingle-0.5 libjingle-0.5.1.zip scons-2.0.1.tar.gz srtp-1.4.4.tgz swtoolkit.0.9.1.zip obj: main.o XmppHandler.o src: main.cc main.o Makefile SConstruct XmppHandler.cc XmppHandler.h XmppSocket.cc XmppSocket.h test:
Voici le répertoire de construction du libjingle:
gtalk_bot/misc/libjingle-0.5.1/talk/build/dbg$ ls * lib: libexpat.a libjingle.a libsrtp.a libxmpphelp.a obj: base call examples libexpat.a libjingle.a libsrtp.a libxmpphelp.a login p2p relayserver session stunserver third_party xmllite xmpp staging: call login relayserver stunserver
La solution
Un grand merci à l'équipe libjingle pour résoudre mon problème. Apparemment, la commande bibliothèque statique est importante. Je viens de commander à nouveau les bibliothèques:
libxmpphelp.a libjingle.a libexpat.a libsrtp.a
"man ld":
L'éditeur de liens va rechercher une archive uniquement une fois, à l'endroit où il est indiqué sur la ligne de commande. Si la archives définit un symbole qui a été undefined dans un objet qui comparu devant l'archive sur la ligne de commande, l'éditeur de liens comprendra le fichier approprié (s) à partir du archiver. Cependant, un symbole non défini dans un objet qui apparaît plus tard sur la ligne de commande ne causera pas l'éditeur de liens pour rechercher à nouveau l'archive.
Maintenant, je suis en mesure de compiler mon application. L'espoir que quelqu'un d'autre va trouver ce utile.