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?

4

2 回答 2

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

libtwitcurl.so.1.这意味着您的编译器在其库目录中找不到。

首先,确保您正确构建了twitcurl库并获得了libtwitcurl.so.1.类似以下内容的文件:

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

其次,确保将文件(或符号链接)放在编译器的库路径之一中:

cp libtwitcurl.so.1.0 /usr/lib/

您可以使用以下命令检查 g++ 库路径:

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

/usr/lib/通常在最后。)

如果您不想/不能将文件放在编译器的库路径中,您还可以libtwitcurl.so.1.通过添加-L/path/to/twitcurl/g++ 选项告诉它在哪里找到,但如果文件已经在编译器的库之一中,则不需要小路。

于 2013-10-10T14:54:47.073 回答
0

您需要指定 twitter 库的路径:

g++ twitterClient.cpp -L/path/to/lib/dir -ltwitcurl
于 2013-10-10T14:56:20.243 回答