Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

c++ - g++ can't link curl lib files

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...