对libcurl函数的未定义引用 [英] Undefined references to libcurl functions

查看:82
本文介绍了对libcurl函数的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法编译,我在Odroid-XU4板上使用Ubuntu.我该如何解决这个问题?感谢您的帮助.

I can't compile, I use Ubuntu on Odroid-XU4 plate. How can I fix this problem? Thanks for any help.

odroid@odroid:~/Desktop/curl_test.2$ g++ -o postit2 postit2.c -lcurl
/tmp/cc4MoKQE.o: In function `main':
postit2.c:(.text+0x2c): undefined reference to `curl_mime_init'
postit2.c:(.text+0x36): undefined reference to `curl_mime_addpart'
postit2.c:(.text+0x48): undefined reference to `curl_mime_name'
postit2.c:(.text+0x56): undefined reference to `curl_mime_filedata'
postit2.c:(.text+0xfa): undefined reference to `curl_mime_free'
collect2: error: ld returned 1 exit status
odroid@odroid:~/Desktop/curl_test.2$ curl --version
curl 7.56.0 (armv7l-unknown-linux-gnueabihf) libcurl/7.47.0 
OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
Release-Date: 2017-10-04
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps 
pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM 
NTLM_WB SSL libz TLS-SRP UnixSockets 

推荐答案

  1. 从源代码安装最新版本的curl.无需删除现有的卷发.默认的configure会将安装置于/usr/local下,但是您可以根据需要将其安装在主目录下,而这不需要root特权. configure 的选项是--prefix =`.
  2. 默认情况下,编译器和链接器均位于/usr/local中.如果您安装在其他地方,则必须告诉工具在哪里.编译器选项将是 -I<目录到安装>/include ,而链接器选项将是 -L<目录到安装的>/lib .
  3. 如果使用动态链接,则必须指定运行时库的位置.通常,运行时加载器在/usr/local下会,因此即使在此安装,也必须指定它.相关的gcc选项为 -Wl,-rpath =< directory-where-libcurl.so-lives-at-run-time> .除非您要针对其他计算机进行编译,否则,该目录将与libcurl.so所在的目录相同.因此,您可能最终两次指定同一目录,并带有-L和-Wl,-rpath选项.
  1. Install the latest version of curl from sources. There is no need to remove your existing curl. The default configure will place the installation under /usr/local, but you can install under your home directory if you want and this doesn't require root privileges. The option to configure is --prefix=`.
  2. The compiler and the linker will both by default look in /usr/local. If you install to a different place, you have to tell the tols where. The compiler option would be -I<directory-to-install>/include and the linker option is -L<directory-to-install>/lib.
  3. If you use dynamic linking, you have to specify where your libraries will be at run time. The runtime loader will not normally look under /usr/local, so you have to specify it even if you install there. The relevant gcc option is -Wl,-rpath=<directory-where-libcurl.so-lives-at-run-time>. Unless you are compiling for a different machine, this is the same directory where libcurl.so is installed, so you might end up specifying the same directory twice, with -L and -Wl,-rpath options.

这篇关于对libcurl函数的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆