2012-04-22 56 views
0

我正在编写使用twitcurl编译的概念C++应用程序(可在https://github.com/paulspencerwilliams/CPlusPlusSocialPlayground处)使用http://code.google.com/p/twitcurl/wiki/WikiHowToUseTwitcurlLibrary上的确切指令进行编译的简单证明。我可以毫无问题地编译和安装twitcurl,并且我可以在Natty Narwhal上编译和执行我的应用程序。然而,解梦山猫编译我的应用程序(通过Makefile)给了我下面的链接问题:Natty Narwhal和Oneiric Ocelot之间共享对象链接的区别

g++ -ltwitcurl twitterClient.cpp -o twitterClient 
/tmp/ccbxmSF3.o: In function `main': 
twitterClient.cpp:(.text+0x1f7): undefined reference to `twitCurl::twitCurl()' 
twitterClient.cpp:(.text+0x22e): undefined reference to `twitCurl::setTwitterUsername(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x247): undefined reference to `twitCurl::setTwitterPassword(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x280): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x292): undefined reference to `oAuth::setConsumerKey(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x2e9): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x2fb): undefined reference to `oAuth::setConsumerSecret(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x50c): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x51e): undefined reference to `oAuth::setOAuthTokenKey(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x52d): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x53f): undefined reference to `oAuth::setOAuthTokenSecret(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x56c): undefined reference to `twitCurl::oAuthRequestToken(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x664): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x676): undefined reference to `oAuth::setOAuthPin(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x691): undefined reference to `twitCurl::oAuthHandlePIN(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
twitterClient.cpp:(.text+0x6a0): undefined reference to `twitCurl::oAuthAccessToken()' 
twitterClient.cpp:(.text+0x6af): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x6c1): undefined reference to `oAuth::getOAuthTokenKey(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x6d0): undefined reference to `twitCurl::getOAuth()' 
twitterClient.cpp:(.text+0x6e2): undefined reference to `oAuth::getOAuthTokenSecret(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x88e): undefined reference to `twitCurl::statusUpdate(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x8ab): undefined reference to `twitCurl::getLastWebResponse(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x8e7): undefined reference to `twitCurl::getLastCurlError(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x97e): undefined reference to `twitCurl::timelineUserGet(bool, bool, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)' 
twitterClient.cpp:(.text+0x9bb): undefined reference to `twitCurl::getLastWebResponse(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0x9f7): undefined reference to `twitCurl::getLastCurlError(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)' 
twitterClient.cpp:(.text+0xa86): undefined reference to `twitCurl::~twitCurl()' 
twitterClient.cpp:(.text+0xc64): undefined reference to `twitCurl::~twitCurl()' 
collect2: ld returned 1 exit status 
make: *** [all] Error 1 

任何想法在编制上这两个平台的区别是什么?为了进行准确的比较,我已经在AWS上的Ubuntu 64位图像上尝试了这一点,并得到相同的症状。

编辑:我已经改变了我的Makefile中的参数顺序,它似乎没有超过第一个问题。然而,在编译时,我现在用以下错误:

g++ twitterClient.cpp -o twitterClient -ltwitcurl 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_easy_getinfo' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_easy_setopt' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_easy_init' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_slist_append' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_slist_free_all' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_easy_perform' 
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libtwitcurl.so: undefined reference to `curl_easy_cleanup' 
collect2: ld returned 1 exit status 
make: *** [all] Error 1 
+0

这听起来像一个链接问题。可能你必须指定其他库,或者用-L选项显式指定库。 试着指定库作为最后一个参数 'gcc test.cpp -o test -ltwitcurl' 否则请尝试检查您尝试链接的库的体系结构。可能它们位于/ usr/lib/libtwitcurl或类似文件中。 如果他们是32位那么你必须指定-m32到gcc我认为 – linello 2012-04-22 20:02:32

+0

可能重复[GCC链接顺序改变?](http://stackoverflow.com/questions/8640642/gcc-link-order-changed) – Lekensteyn 2012-04-22 20:08:29

+0

它是一个链接问题,我已经改变了参数的顺序,但是这导致了第二个问题。我按照原文编辑了我的原文。 – 2012-04-23 07:37:42

回答

4

较新的版本gcc的解梦需要链接参数的源文件后,设置:

g++ twitterClient.cpp -o twitterClient -ltwitcurl 
+0

干杯!我已经改变了命令行顺序,但现在在编辑的原始文章中得到第二个错误。 – 2012-04-23 07:38:33

+0

使用twitcurl发布的Makefile与我的类似问题。我改变了g ++命令行,最后应用-lcurl,现在应用程序编译并运行在Oneiric Ocelot上。 – 2012-04-23 09:18:28