g++ 无法链接 curl lib 文件 [英] g++ can't link curl lib files
问题描述
我在使用 g++ 链接 curl lib 文件时遇到了一些问题.我使用的是带有 linux dev 插件和 Ubuntu Server 17.04 的 Visual Studio 2017.
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
给出了 -Lcurl
的输出,我尝试将其添加到 Project settings > 中的链接器选项中.链接器命令行 >附加选项
.我还在编译选项中添加了 --cflags
输出.这并没有解决问题.
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.
然后我尝试了网站上的源代码并使用了 make 和 make install.curl-config --libs
给了我 -L/usr/local/lib -lcurl
的不同输出.我更改了链接器中的选项,但这仍然不起作用.
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.
链接器输出显示了很多未定义的对"的引用,然后是 curl 方法.我在 cpp 文件中有 #include
.
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
推荐答案
使用默认安装,您将使用 -lcurl<指定
curl
库到 gcc
/code>,由 curl-config --libs
报告.并且要在 VCLinux 生成的 gcc
命令行上传递它,将 curl
添加到 Additional Library Dependencies 下的行Linker/Input 在 VS 项目属性中.请注意,您只输入 curl,VCLinux 提供 -l
并且 gcc 链接器将其扩展为 libcurl.a
的实际文件名(或 libcurl.so
(如果您要链接共享库).
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).
您通常不必指定库搜索路径,因为 /usr/lib
等会自动在库搜索路径上.例如,在 Debian 9 上,libcurl.a
位于 /usr/lib/i386-linux-gnu
中.但是如果你在非标准的地方安装 curl,在 Linker/General 下添加 Additional Library Directory 的路径.如果您是从 Linux 发行版安装 curl,请记住也要安装开发文件;在 Debian 上,这是包 libcurl4-gnutls-dev
.
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 与 pkg-config
兼容,因此,作为直接输入路径和库名称的替代方法,您可以指定 %24(pkg-config --cflags libcurl)C++/所有选项/附加选项和
%24(pkg-config --libs libcurl)
中的代码>在链接器/所有选项/附加选项中.请注意,%24
是经过编码的 $
,否则 Visual Studio 会尝试(但失败)将该字符串解释为宏.
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屋!