I’m having some issues with getting g++ to link the curl lib files. I’m using Visual Studio 2017 with the linux dev plugin and Ubuntu Server 17.04.
curl-config --libs
gave an output of -Lcurl
which I tried adding to the linker options in Project settings > Linker > Command Line > Additional options
. I also added the --cflags
output to the compile options. This didn’t fix the issue.
Then I tried the source from the website and used make and make install. curl-config --libs
gave me a different output of -L/usr/local/lib -lcurl
. I changed the options in the linker and this still didn’t work.
The linker output says lots of “undefined reference to ” and then the curl methods. I have #include <curl/curl.h>
in the cpp file.
Any ideas?
Thanks
Advertisement
Answer
With a default installion you will specify the curl
library to gcc
with -lcurl
, as reported by curl-config --libs
. And to pass this on the gcc
command line generated by VCLinux, add curl
to the Additional Library Dependencies line under Linker / Input in the VS project properties. Note that you enter just curl, VCLinux supplies the -l
and the gcc linker expands it to the actual filename of libcurl.a
(or libcurl.so
if you’re linking a shared library).
You do not normally have to specify the library search path since /usr/lib
etc. are automatically on the library search path. On Debian 9 for example, libcurl.a
is in /usr/lib/i386-linux-gnu
. But if you install curl somewhere non-standard, add the path to Additional Library Directories under Linker / General. If you are installing curl from your Linux distribution, remember to install the development files as well; on Debian this is the package libcurl4-gnutls-dev
.
curl is compatible with pkg-config
so, as an alternative to entering the paths and library names directly, you can specify %24(pkg-config --cflags libcurl)
in C++ / All Options / Additional Options and %24(pkg-config --libs libcurl)
in Linker / All Options / Additional Options.
Note that %24
is an encoded $
because otherwise Visual Studio tries (and fails) to interpret the string as a macro.