g ++无法链接curl lib文件 [英] g++ can't link curl lib files
问题描述
获取g ++链接curl lib文件时遇到一些问题.我正在将Visual Studio 2017与linux dev插件和Ubuntu Server 17.04一起使用.
curl-config --libs
给出了-Lcurl
的输出,我尝试将其添加到Project settings > Linker > Command Line > Additional options
中的链接器选项中.我还将--cflags
输出添加到了编译选项.这不能解决问题.
然后,我尝试了网站上的源代码,并使用了make和make install. curl-config --libs
给了我-L/usr/local/lib -lcurl
的不同输出.我更改了链接器中的选项,但仍然无法正常工作.
链接器输出显示许多未定义的引用",然后显示curl方法.我的cpp文件中有#include <curl/curl.h>
.
有什么想法吗?
谢谢
对于默认安装,您将使用-lcurl
将curl
库指定为gcc
,如curl-config --libs
所报告.并在VCLinux生成的gcc
命令行中传递此代码,请将curl
添加到 Linker /<下的 Additional 库依赖项行中VS项目属性中的em> Input .请注意,您仅输入 curl ,VCLinux提供了-l
,gcc链接器将其扩展为实际的文件名libcurl.a
(如果要链接共享库,则为libcurl.so
). /p>
通常不需要指定库搜索路径,因为/usr/lib
等会自动出现在库搜索路径上.例如,在Debian 9上,libcurl.a
位于/usr/lib/i386-linux-gnu
中.但是,如果在非标准位置安装curl,请在 Linker / General 下将路径添加到其他库目录.如果要从Linux发行版安装curl,请记住也要安装开发文件.在Debian上,这是软件包libcurl4-gnutls-dev
.
curl与pkg-config
兼容,因此,除了直接输入路径和库名称之外,您还可以在 C ++ /所有选项/中指定%24(pkg-config --cflags libcurl)
链接器/所有选项/其他选项中的其他选项和%24(pkg-config --libs libcurl)
.
请注意,%24
是编码的$
,因为否则Visual Studio会尝试(失败)将字符串解释为宏.
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 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.
这篇关于g ++无法链接curl lib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!