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
With a default installion you will specify the
curl
library togcc
with-lcurl
, as reported bycurl-config --libs
. And to pass this on thegcc
command line generated by VCLinux, addcurl
to theAdditionalLibrary 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 oflibcurl.a
(orlibcurl.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 packagelibcurl4-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.Is it because there's no h after the . in your include? Other than that, Visual Studio also needs to know the search path for your headers and libraries. It can search the build output or some of its default directories which are the VC++ directories. Beyond that you have to tell it where to search, by using some of the other menus close by.