0

I want to compile a C++ program with a twitter library, on Linux.

I'm current using twitcurl as the twitter API library and installed g++ and all the necessary files and packages that are listed on the official website: http://code.google.com/p/twitcurl/wiki/WikiHowToUseTwitcurlLibrary

However, when I compile my program using this command g++ twitterClient.cpp -ltwitcurl, I get this error: cannot find -ltwitcurl

I also used CodeBlocks IDE to compile it but got this error: undefined reference to twitCurl::~twitCurl() `

My code only contains a few lines:

#include <iostream>
#include "Twitter/Twitter.hpp"
using namespace std ;

int main ()
{
    Twitter t ;
    return 0 ; 
}

I've already spent a lot of time on this but am unable to solve the problem. What should I do in order to compile the program on the command-line and CodeBlocks?

BroVic
  • 979
  • 9
  • 26
user2649244
  • 111
  • 2
  • 7

2 Answers2

1
$ g++ twitterClient.cpp -ltwitcurl
cannot find -ltwitcurl

This means your compiler doesn't find the libtwitcurl.so.1. in its library directories.

First, make sure you correctly build the twitcurl library and obtained the libtwitcurl.so.1. file with something like this :

svn co http://twitcurl.googlecode.com/svn/trunk/libtwitcurl
cd libtwitcurl/
make

Secondly, make sure you put the file (or a symlink) in one of your compiler's library path :

cp libtwitcurl.so.1.0 /usr/lib/

You can check g++ library paths using the following command :

g++ --print-search-dirs | grep libraries

(/usr/lib/ is usually at the end.)

If you don't want/can't put the file in your compiler's library path, you can also tell it where to find libtwitcurl.so.1. by adding -L/path/to/twitcurl/ in the g++ options, but it is not needed if the file is already in one of the compiler's library path.

zakinster
  • 10,508
  • 1
  • 41
  • 52
  • I already copy the libtwitcurl.so.1. into /usr/lib/ but still shown "cannot find -ltwitcurl" If i want to use the last option, the command is like this ? "g++ twitterClient.cpp -L/usr/lib/ -ltwitcurl" – user2649244 Oct 10 '13 at 15:38
0

You need to specify path to twitter lib:

g++ twitterClient.cpp -L/path/to/lib/dir -ltwitcurl
Iuri Covalisin
  • 645
  • 4
  • 7