Problem Using libcurl and SCons C++
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"
#inc开发者_运维百科lude "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?
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.
That is a linker error, nothing to do with compilation. Are you linking against the curl libraries?
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.
精彩评论