Undefined references to libcurl functions

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 

Upvotes: 4

Views: 3181

Answers (2)

n. m. could be an AI
n. m. could be an AI

Reputation: 120229

  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.

Upvotes: 1

boriaz50
boriaz50

Reputation: 856

Linker looks for libcurl in its configured path and it finds old version first.

Edit /etc/ld.so.conf to make the linker looks for in directory with new libculr version.

Or reinstall libcurl:

sudo apt-get remove libcurl
wget http://curl.haxx.se/download/curl-7.56.0.tar.gz
./configure
make
make install

Upvotes: 0

Related Questions