Trouble Compiling File from Linux Package

Trouble Compiling File from Linux Package

Post by Israel on Mon Jun 22, 2009 3:45 pm
([msg=25761]see Trouble Compiling File from Linux Package[/msg])

Having trouble compiling this file. I think I need to link a compiler package to g++ but not sure.

Here is the code:
Code: Select all
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <errno.h>
#include <fcntl.h>
#include <QDir>
#include <QFile>
#include <kurl.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include "app.h"
#include "btversion.h"
#include "ktversion.h"
#include <kdebug.h>

#ifndef Q_WS_WIN
bool GrabPIDLock()
{
   // open the PID file in the /tmp directory and attempt to lock it
   QString pid_file = QString(QDir::tempPath()+"/.ktorrent_kde4_%1.lock").arg(getuid());

   int fd = open(QFile::encodeName(pid_file),O_RDWR|O_CREAT,0640);
   if (fd < 0)
   {
      fprintf(stderr,"Failed to open KT lock file %s : %s\n",pid_file.toAscii().constData(),strerror(errno));
      return false;
   }

   if (lockf(fd,F_TLOCK,0)<0)
   {
      fprintf(stderr,"Failed to get lock on %s : %s\n",pid_file.toAscii().constData(),strerror(errno));
      return false;
   }
      
   char str[20];
   sprintf(str,"%d\n",getpid());
   write(fd,str,strlen(str)); /* record pid to lockfile */

   // leave file open, so nobody else can lock it until KT exists
   return true;
}
#endif


int main(int argc, char **argv)
{
#ifndef Q_WS_WIN
   // ignore SIGPIPE and SIGXFSZ
   signal(SIGPIPE,SIG_IGN);
   signal(SIGXFSZ,SIG_IGN);
#endif

   bt::SetClientInfo("KTorrent",kt::MAJOR,kt::MINOR,kt::RELEASE,bt::NORMAL,"KT");
   
   KAboutData about(
      "ktorrent", 0, ki18n("KTorrent"),
      kt::VERSION_STRING, ki18n("Bittorrent client for KDE"),
      KAboutData::License_GPL,
      ki18n("(C) 2005 - 2008 Joris Guisson and Ivan Vasic"),
      KLocalizedString(),
      "http://www.ktorrent.org/");

   about.addAuthor(ki18n("Joris Guisson"), KLocalizedString(), "joris.guisson@gmail.com","http://ktorrent.org" );
   about.addAuthor(ki18n("Ivan Vasic"),KLocalizedString(),"ivasic@gmail.com");
   about.addAuthor(ki18n("Alan Jones"),ki18n("BitFinder Plugin"),"skyphyr@gmail.com");
   about.addAuthor(ki18n("Diego R. Brogna"),ki18n("Webinterface Plugin"),"dierbro@gmail.com");
   about.addAuthor(ki18n("Krzysztof Kundzicz"),ki18n("Statistics Plugin"),"athantor@gmail.com");

   about.addCredit(ki18n("Mladen Babic"),   ki18n("Application icon and a couple of others"),"bmladen@EUnet.yu");
   about.addCredit(ki18n("Adam Treat"), KLocalizedString(), "treat@kde.org" );
   about.addCredit(ki18n("Danny Allen"),ki18n("1.0 application icon"),"danny@dannyallen.co.uk");
   about.addCredit(ki18n("Vincent Wagelaar"),KLocalizedString(),"vincent@ricardis.tudelft.nl");
   about.addCredit(ki18n("Knut Morten Johansson"),KLocalizedString(),"knut@johansson.com");
   about.addCredit(ki18n("Felix Berger"),   ki18n("ChunkBar's tooltip and IWFileTreeItem sorting"),"bflat1@gmx.net");
   about.addCredit(ki18n("Andreas Kling"),KLocalizedString(),"kling@impul.se");
   about.addCredit(ki18n("Felipe Sateler"),KLocalizedString(),"fsateler@gmail.com");
   about.addCredit(ki18n("Maxmind"), ki18n("Country locator for InfoWidget plugin. Flags are taken from http://flags.blogpotato.de/ so thanks to them too."),0, "http://www.maxmind.com/");
   about.addCredit(ki18n("Adam Forsyth"),ki18n("File prioritization"),"agforsyth@gmail.com");
   about.addCredit(ki18n("Thomas Bernard"),ki18n("Miniupnp was used as an example for our own UPnP implementation"),0,"http://miniupnp.free.fr/");
   about.addCredit(ki18n("Diego Rosario Brogna"),ki18n("Global max share ratio patch"),0,"dierbro@gmail.com");
   about.addCredit(ki18n("Lesly Weyts"),ki18n("Zeroconf enhancements"),0,0);
   about.addCredit(ki18n("Kevin Andre"),ki18n("Zeroconf enhancements"),0,"http://users.edpnet.be/hyperquantum/");
   about.addCredit(ki18n("Dagur Valberg Johannsson"),ki18n("Coldmilk webgui"),"dagurval@pvv.ntnu.no");
   about.addCredit(ki18n("Alexander Dymo"),ki18n("IDEAl code from KDevelop"),"adymo@kdevelop.org");
   about.addCredit(ki18n("Scott Wolchok"),ki18n("Conversion speed improvement in ipfilter plugin"),"swolchok@umich.edu");
   about.addCredit(ki18n("Bryan Burns of Juniper Networks"),ki18n("Discovered 2 security vulnerabilities (both are fixed)"),0);
   about.addCredit(ki18n("Goten Xiao"),ki18n("Patch to load silently with a save location"),0);
   about.addCredit(ki18n("Rapsys"),ki18n("Fixes in PHP code of webinterface"),0);
   about.addCredit(ki18n("Athantor"),ki18n("XFS specific disk preallocation"),0);
   about.addCredit(ki18n("twisted_fall"),ki18n("Patch to not show very low speeds"),"twisted.fall@gmail.com");
   about.addCredit(ki18n("Lucke"),ki18n("Patch to show potentially firewalled status"),0);
   about.addCredit(ki18n("Modestas Vainius"),ki18n("Several patches"),"modestas@vainius.eu");
   about.addCredit(ki18n("Stefan Monov"),ki18n("Patch to hide menu bar"),"logixoul@gmail.com");
   about.addCredit(ki18n("The_Kernel"),ki18n("Patch to change file priorities in the webgui"),"kernja@cs.earlham.edu");
   about.addCredit(ki18n("Rafał Miłecki"),ki18n("Several webgui patches"),"zajec5@gmail.com");
   about.addCredit(ki18n("Ozzi"),ki18n("Fixes for several warnings"),"ossi@masiina.no-ip.info");
   about.addCredit(ki18n("Markus Brueffer"),ki18n("Patch to fix free diskspace calculation on FreeBSD"),"markus@brueffer.de");
   about.addCredit(ki18n("Lukas Appelhans"),ki18n("Patch to fix a crash in ChunkDownloadView"),"l.appelhans@gmx.de");
   about.addCredit(ki18n("Rickard Närström"),ki18n("A couple of bugfixes"),"rickard.narstrom@gmail.com");
   about.addCredit(ki18n("caruccio"),ki18n("Patch to load torrents silently from the command line"),"mateus@caruccio.com");
   about.addCredit(ki18n("Lee Olson"),ki18n("New set of icons"),"leetolson@gmail.com");
   KCmdLineArgs::init(argc, argv, &about);

   KCmdLineOptions options;
   options.add("+[Url]", ki18n("Document to open"));
   options.add("silent", ki18n("Silently open torrent given on URL"));
   KCmdLineArgs::addCmdLineOptions(options);
   
   kt::App::addCmdLineOptions();
   if (!kt::App::start())
   {
      fprintf(stderr, "ktorrent is already running !\n");
      return 0;
   }

#ifndef Q_WS_WIN   
   // need to grab lock after the fork call in start, otherwise this will not work properly
   if (!GrabPIDLock())
   {
      fprintf(stderr, "ktorrent is already running !\n");
      return 0;

   }
#endif

#ifdef Q_WS_WIN
   WSADATA wsaData;
   WORD wVersionRequested = MAKEWORD(2, 2);
   int err = WSAStartup( wVersionRequested, &wsaData );
   if (err != 0)
   {
      kError()<< "Couldn't load winsock dll";
      return 0;
   }
#endif

   try
   {
      kt::App app;
      app.setQuitOnLastWindowClosed(false);
      app.exec();
   }
   catch (...)
   {
   //   fprintf(stderr, "Aborted by error : %s\n",e.toString().ascii());
   }
   return 0;
}


Here are my errors:
Code: Select all
# g++ -o
main.cpp:30:16: error: QDir: No such file or directory
main.cpp:31:17: error: QFile: No such file or directory
main.cpp:32:18: error: kurl.h: No such file or directory
main.cpp:33:21: error: klocale.h: No such file or directory
main.cpp:34:24: error: kaboutdata.h: No such file or directory
main.cpp:35:26: error: kcmdlineargs.h: No such file or directory
In file included from main.cpp:36:
app.h:24:32: error: kuniqueapplication.h: No such file or directory
main.cpp:37:23: error: btversion.h: No such file or directory
main.cpp:38:23: error: ktversion.h: No such file or directory
main.cpp:39:20: error: kdebug.h: No such file or directory
In file included from main.cpp:36:
app.h:31: error: expected class-name before '{' token
app.h:32: error: ISO C++ forbids declaration of 'Q_OBJECT' with no type
app.h:33: error: expected ';' before 'public'
main.cpp: In function 'bool GrabPIDLock()':
main.cpp:45: error: 'QString' was not declared in this scope
main.cpp:45: error: expected `;' before 'pid_file'
main.cpp:47: error: 'QFile' has not been declared
main.cpp:47: error: 'pid_file' was not declared in this scope
main.cpp:50: error: 'strerror' was not declared in this scope
main.cpp:56: error: 'strerror' was not declared in this scope
main.cpp:62: error: 'strlen' was not declared in this scope
main.cpp: In function 'int main(int, char**)':
main.cpp:78: error: 'bt' has not been declared
main.cpp:78: error: 'MAJOR' is not a member of 'kt'
main.cpp:78: error: 'MINOR' is not a member of 'kt'
main.cpp:78: error: 'RELEASE' is not a member of 'kt'
main.cpp:78: error: 'bt' has not been declared
main.cpp:80: error: 'KAboutData' was not declared in this scope
main.cpp:80: error: expected `;' before 'about'
main.cpp:88: error: 'about' was not declared in this scope
main.cpp:88: error: 'ki18n' was not declared in this scope
main.cpp:88: error: 'KLocalizedString' was not declared in this scope
main.cpp:127: error: 'KCmdLineArgs' has not been declared
main.cpp:129: error: 'KCmdLineOptions' was not declared in this scope
main.cpp:129: error: expected `;' before 'options'
main.cpp:130: error: 'options' was not declared in this scope
main.cpp:132: error: 'KCmdLineArgs' has not been declared
main.cpp:134: error: 'addCmdLineOptions' is not a member of 'kt::App'
main.cpp:135: error: 'start' is not a member of 'kt::App'
app.h:35: error: 'virtual kt::App::~App()' is private
main.cpp:164: error: within this context
main.cpp:165: error: 'class kt::App' has no member named 'setQuitOnLastWindowClo
main.cpp:166: error: 'class kt::App' has no member named 'exec'
User avatar
Israel
Experienced User
Experienced User
 
Posts: 74
Joined: Thu Sep 18, 2008 9:53 pm
Blog: View Blog (0)


Re: Trouble Compiling File from Linux Package

Post by BhaaL on Tue Jun 23, 2009 11:28 am
([msg=25815]see Re: Trouble Compiling File from Linux Package[/msg])

If you did some googling, you'd know that QDir and QFile are part of Qt, while kurl and the others are from KDE.
You'd need the development packages of each of those installed to compile that.
BhaaL
Poster
Poster
 
Posts: 270
Joined: Sun Apr 13, 2008 11:16 am
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests

cron