c++ - How to get rid of libcurl linking error? -
i using libcurl version 7.19 in cpp application. trying use example given kukuruku.co. when try build application getting following errror,
lib/libcurl.a(libcurl_la-http_negotiate.o): in function `cleanup': http_negotiate.c:(.text+0x1b): undefined reference `gss_delete_sec_context' http_negotiate.c:(.text+0x30): undefined reference `gss_release_buffer' http_negotiate.c:(.text+0x45): undefined reference `gss_release_name' lib/libcurl.a(libcurl_la-http_negotiate.o): in function `curl_output_negotiate': http_negotiate.c:(.text+0x123): undefined reference `gss_release_buffer' http_negotiate.c:(.text+0x1c0): undefined reference `gss_release_buffer' lib/libcurl.a(libcurl_la-http_negotiate.o): in function `curl_input_negotiate': http_negotiate.c:(.text+0x324): undefined reference `gss_c_nt_hostbased_service' http_negotiate.c:(.text+0x33a): undefined reference `gss_import_name' http_negotiate.c:(.text+0x48e): undefined reference `gss_release_buffer' http_negotiate.c:(.text+0x4cc): undefined reference `gss_release_buffer'
here code snippet using ,
#include <stdio.h> #include <curl/curl.h> int main(void) { curl *curl; curlcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, curlopt_url, "http://example.com"); /* example.com redirected, tell libcurl follow redirection */ curl_easy_setopt(curl, curlopt_followlocation, 1l); /* perform request, res return code */ res = curl_easy_perform(curl); /* check errors */ if(res != curle_ok) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* cleanup */ curl_easy_cleanup(curl); } return 0; }
my makefile looks this,
ccflags = -g -wall -pthread -d_largefile_source -d_file_offset_bits=64 -d__stdc_format_macros -d__stdc_limit_macros -duse_apache2 -fno-strict-aliasing -fmessage-length=0 -fpic - o0 -ftemplate-depth-32 -fno-operator-names -d_gnu_source -d_gss_c_nt_hostbased_service cflags += `pkg-config --cflags libcurl` ldflags += `pkg-config --libs libcurl` #dcmake_build_type=release #libs += -libcurl
i use module.mk file target,
app_objects = \ app-client/app-client-cmd.o \ $(null)
could me on this?
you should provide linker options, e.g.
gcc -wall -o2 -g -lcurl -o test main.cpp
or use pkg-config
. in linux shell may following:
gcc -wall -o2 -g $(pkg-config --libs --cflags libcurl) -o test main.cpp
update: static linking
as @drew010 suggested, can generate proper linker options curl-config
:
cc=$(curl-config --cc) $cc -wall -g -o2 main.cpp $(curl-config --static-libs) -o mytest
update: added makefile , cmake examples
using makefile
cc = gcc cflags = -wall -g -o2 ldflags = executable = mytest sources = main.cpp cflags += `pkg-config --cflags libcurl` ldflags += `pkg-config --libs libcurl` all: $(executable) $(executable): $(sources) $(cc) $(sources) -o $@ $(ldflags) .cpp.o: $(cc) $(cflags) $< -o $@ clean: rm -f $(objects) $(executable)
using cmake
cmake_minimum_required (version 2.6) project (myproject cxx) set(cmake_build_type "release") include_directories("${cmake_current_source_dir}") set(cmake_runtime_output_directory "${cmake_binary_dir}/bin") include(findcurl) find_package(curl required) if (not curl_found) message (fatal_error "curl not supported") endif (not curl_found) include_directories(curl_include_dirs) set(cmake_required_libraries "${curl_libraries}") list(append libs "${curl_libraries}") set(target "mytest") add_executable(${target} main.cpp) target_link_libraries(${target} ${libs}) install(targets ${target} destination "bin")
Comments
Post a Comment