开发者

gcc won't include libcurl on commandline for OS X

开发者 https://www.devze.com 2023-03-21 11:41 出处:网络
I\'m trying to compile a C project I\'ve been working on on a remote server that runs OS X.The project depends, in part, on libcurl开发者_如何学JAVA.I only have access to the machine through my admini

I'm trying to compile a C project I've been working on on a remote server that runs OS X. The project depends, in part, on libcurl开发者_如何学JAVA. I only have access to the machine through my administrator account remotely.

When I attempt to make the project I keep getting errors relating to libcurl functions and constants not being defined. I conclude that libcurl is not being properly included by the compiler.

I'm using fink to install opensource software for all the dependencies ( postgres, curl, a few others ) and all the dependencies appear to work except curl.

My compiler command looks like:

gcc -ggdb -ansi -Wall -D_GNU_SOURCE -L `/sw/bin/pg_config --libdir` `/sw/bin/curl-config --cflags` -I `/sw/bin/pg_config --includedir` -lpq -lcurl -lpthread -lm `/sw/bin/curl-config --libs` -c Client.c

If I make a test file like so:

/sw/bin/curl http://www.google.com/ --libcurl test.c

And then attempt to compile it with:

gcc test.c `/sw/bin/curl-config --cflags` `/sw/bin/curl-config --libs` -o test.o

It also fails. Can anyone help me shed some light on this problem?


One compilation line is:

gcc -ggdb -ansi -Wall -D_GNU_SOURCE -L `/sw/bin/pg_config --libdir` \
    `/sw/bin/curl-config --cflags` -I `/sw/bin/pg_config --includedir` \
    -lpq -lcurl -lpthread -lm `/sw/bin/curl-config --libs` -c Client.c

This will take Client.c and generate Client.o, an object file. It doesn't need the library information; there is no linking taking place because of the -c option.

The other compilation line is:

gcc test.c `/sw/bin/curl-config --cflags` `/sw/bin/curl-config --libs` -o test.o

It is aconventional to end the names of executables with '.o'; it leads to confusion. However, if test.c only references functions from the standard libraries and libcurl, it should 'work'.

On my Mac, there is a copy of curl-config in /usr/bin.


Try this test program:

$ cat curltest.c
#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    if (curl_global_init(0) == CURLE_OK)
    {
        printf("CURL version %s\n", curl_version());
        curl_global_cleanup();
    }
    else
        fprintf(stderr, "Failed to initialize CURL\n");

    return 0;
}
$ cc -o curltest $(curl-config --cflags) curltest.c $(curl-config --libs)
$ file curltest
curltest: Mach-O 64-bit executable x86_64
$ otool -L curltest
curltest:
    /usr/lib/libcurl.4.dylib (compatibility version 6.0.0, current version 6.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
$ curltest
CURL version libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
$

This is on MacOS X 10.6.8.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号