使用 libcurl 和 SCons C++ 时出现问题

发布于 2024-11-09 20:55:52 字数 729 浏览 6 评论 0原文

我的问题与这个非常相似: https://stackoverflow.com/questions/4351877/link-libcurl-library-using-scons< /a>

我有一个 C++ 程序,必须使用 SCons 进行编译,并且我正在尝试使用 libcurl 将发布消息发送到服务器。我已将库与此链接:

#include "curl/curl.h"
#include "curl/types.h"
#include "curl/easy.h"

问题出现在此处(从主网站获取的代码):

CURL *curl;
CURLcode res;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);

当我尝试编译时出现以下错误: 对“curl_global_init”的未定义引用

我已经在这个问题上坚持了一个星期了,知道如何解决这个问题吗?

My question is very similar to this one:
https://stackoverflow.com/questions/4351877/link-libcurl-library-using-scons

I have a C++ program I have to compile using SCons, and I'm trying to use libcurl to send post messages to a server. I've linked the libraries with this:

#include "curl/curl.h"
#include "curl/types.h"
#include "curl/easy.h"

The issue comes up around here (code taken off the main website):

CURL *curl;
CURLcode res;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);

I get the following error when I try to compile:
undefined reference to `curl_global_init'

I've been stuck on this for a week now, any idea how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

耀眼的星火 2024-11-16 20:55:52

这是一个链接错误,发生这种情况是因为您可能没有告诉链接器将您的应用程序与 libcurl 链接,或者您没有指定正确的目录来查找它。

检查与库链接 在文档上。

编辑:

在我做的一个小测试中,SConstruct看起来像这样:

Program('mycurl.c', LIBS='curl', 
                    LIBPATH=['/usr/lib', '/usr/local/lib'])

使用scons -Q编译成功并打印:

gcc -o mycurl.o -c mycurl.c
gcc -o mycurl mycurl.o -L/usr/lib -L/usr/local/lib -lcurl

这正是你会手动做。

This is a link error, and it's happening because you probably didn't told the linker to link your application with libcurl, or you didn't specify the right directory for it to find it.

Check the section Linking with Libraries on the docs.

EDIT:

On a small test I did, the SConstruct looks like this:

Program('mycurl.c', LIBS='curl', 
                    LIBPATH=['/usr/lib', '/usr/local/lib'])

And compiling with scons -Q succeeds and prints:

gcc -o mycurl.o -c mycurl.c
gcc -o mycurl mycurl.o -L/usr/lib -L/usr/local/lib -lcurl

which is exactly what you would do manually.

人事已非 2024-11-16 20:55:52

这是一个链接器错误,与编译无关。您是否链接到curl 库?

That is a linker error, nothing to do with compilation. Are you linking against the curl libraries?

放血 2024-11-16 20:55:52

我自己从未使用过 scons,但我发现此链接包含有关使用 scons 链接库的简短教程。

http://www.scons.org/doc/0.97/HTML /scons-user/x628.html

我希望这有帮助。

I've never used scons myself, but I found this link with a short tutorial on linking in libraries with scons.

http://www.scons.org/doc/0.97/HTML/scons-user/x628.html

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文