Troubles with Curlpp
On Mint 17 I was able to compile and run your program using
g++ main.cpp -lcurl -lcurlpp
Looking at a library dump of the program, you may be missing the following libraries which you can install with apt-get
:
libssl-1.0.0
libcurl4-openssl-dev
LD Dump
$ ldd a.out
linux-vdso.so.1 => (0x00007fff701fe000)
libcurlpp.so.0 => /usr/lib/x86_64-linux-gnu/libcurlpp.so.0 (0x00007f896cd05000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f896c9f7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f896c7df000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f896c41a000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f896c1b3000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f896beac000)
/lib64/ld-linux-x86-64.so.2 (0x00007f896cf68000)
libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007f896bc79000)
librtmp.so.0 => /usr/lib/x86_64-linux-gnu/librtmp.so.0 (0x00007f896ba5f000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f896b7ff000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f896b424000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f896b1dd000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f896afcd000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f896ad7c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f896ab63000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f896a944000)
libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007f896a686000)
libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007f896a406000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f896a201000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f8969f36000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f8969d07000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f8969b02000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f89698f7000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f89696dc000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f89694c0000)
libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f8969282000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f896906e000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f8968e2b000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f8968c26000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f8968a22000)
libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f8968818000)
libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f8968590000)
libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f89682ee000)
libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f89680bb000)
libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f8967ea6000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f8967c9d000)
libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f8967a74000)
libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f8967866000)
libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f896761c000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f8967363000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f896712a000)
CURLpp, segmentation fault
There was extra library curl-7.45
, which i had to delete and update other libraries.
Commands:
$ sudo rm libcurl.so.4.4.0 //(in usr/local/lib)
$ sudo apt-get update
$ sudo apt-get install libcurl4-openssl-dev //(Optionally)
Thanks to @KnudLarsen
How do I link libcurl to my c++ program in linux?
Your header file inclusions are just fine; your problem is occurring at the linking step. In order to link against libcurl, you need to add the -lcurl
command line option, assuming it's installed in a standard directory:
g++ -o sms ./src/sms.o -lcurl
If it's not installed in a standard directory, you also need to add the -L/path/to/libcurl
, e.g. something like:
# Assuming that /home/geekman/workspace/libcurl is where libcurl.a is located
g++ -o sms ./src/sms.o -L/home/geekman/workspace/libcurl -lcurl
Also note that the -lcurl
option has to appear after the list of object files you're linking, otherwise it won't link properly.
Compile issues with curlpp: undefined reference to symbol 'curl_easy_setopt@@CURL_OPENSSL_3'
I found the dumb fix. I'll leave this up in case someone else has the same issue. You must compile with:
g++ file.cpp -lcurlpp -lcurl
Link errors with curlpp
The problem is that linkage of ccurlcpp::UnsetOption::UnsetOption
is partially defective in the lipcurlcpp.so
binary.
The linker's complaint with:
g++ -o example00 example00.cpp -lm -lcurl -lcurlpp
is:
undefined reference to `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
But if I demangle the constructor signatures in libcurlpp.so
:
nm -D -C libcurlpp.so | grep UnsetOption::UnsetOption
I see:
0000000000021776 T curlpp::UnsetOption::UnsetOption(char const*)
000000000002173e T curlpp::UnsetOption::UnsetOption(std::string const&)
The std::string
hasn't been properly de-typedefed for some reason. If
I get the source file in which this constructor is defined from thecurlpp 0.7.3
source package, Exception.cpp
, compile it:
curlpp-0.7.3/src/curlpp$ g++ -I../../include -I. -c Exception.cpp
and then demangle the constructor signatures from the object file:
nm -C Exception.o | grep UnsetOption::UnsetOption
I get:
00000000000003f4 T curlpp::UnsetOption::UnsetOption(char const*)
00000000000003c2 T curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
So:
curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
is the signature the compiler is telling the linker to look for, but that is
not the signature in the library. The short explanation of the error is: the library is broken.
However, we see that no such inconsistency affects the other overload of the constructor:
curlpp::UnsetOption::UnsetOption(char const*)
nor could it, since the char const *
is a builtin type.
This enables a hack fix. The file in which the undefined-reference call is
compiled is (as installed) /usr/include/curlpp/Option.inl
, at the line:
throw UnsetOption(std::string("You are trying to set an unset option to a handle"));
Edit this file, as root, and you see that it (inconsistently) contains two instances
of:
throw UnsetOption(std::string("blah blah"));
and one instance of:
throw UnsetOption("blah blah");
Change the occurrences of UnsetOption(std::string("blah blah"))
to UnsetOption("blah blah")
.
Then only the good constructor is called in this file and example00
, at least, will
compile and link.
If you dislike the hack, or find that the problem re-surfaces elsewhere, then you
may download the ubuntu source package curlpp_0.7.3.orig.tar.gz
and build and install it yourself. That is the right remedy.
Related Topics
How to Read Linux File Permission Programmatically in C/C++
Hide or Crop Overlapping Text in Qlabel
Q_Object Throwing 'Undefined Reference to Vtable' Error
End of File(Eof) of Standard Input Stream (Stdin)
What Does Template <Unsigned Int N> Mean
Send and Receive a File in Socket Programming in Linux with C/C++ (Gcc/G++)
Why Is Including "Using Namespace" into a Header File a Bad Idea in C++
Access Variable Value Using String Representing Variable's Name in C++
What's the Difference Between "Static" and "Dynamic" Schedule in Openmp
Colour Output of Program Run Under Bash
Is There a Decent Wait Function in C++
Is String::C_Str() No Longer Null Terminated in C++11
Colorizing Text in the Console with C++
When G++ Static Link Pthread, Cause Segmentation Fault, Why