首页 > 解决方案 > g++ Mac Curl 架构 x86_64 的未定义符号

问题描述

我正在学习与 curl 相关的在线课程。但是,我遇到了一些问题。

我的建筑声明是:

gcc -Wall web-server.c -o web-server1 -lcurl

这是 web-server.c 中的代码

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
int main(void){
    CURL *curl = NULL;
    CURLcode res;

    curl = curl_easy_init();

    curl_easy_setops(curl, CURLOPT_URL, "http://www.google.com");


    res = curl_easy_perform(curl);
    if (res != CURLE_OK){
        print("curl easy perform error res = %d",res);
        return 1;
    }

    curl_easy_cleanup(curl);
    return 0;
}

错误信息是:

Undefined symbols for architecture x86_64:
  "_curl_easy_setops", referenced from:
      _main in web-server-afa9ad.o
  "_print", referenced from:
      _main in web-server-afa9ad.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

非常感谢你们 我的操作系统是 MacOs 10.14.6 我的 gcc 版本

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Found CUDA installation: /usr/local/cuda, version unknown

详细的错误信息

 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library 
/Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -
dynamic -arch x86_64 -macosx_version_min 10.14.0 -o web-server 
/var/folders/j2/jrqt57vj73s0jc8mjc2mddf40000gn/T/web-server-14b13c.o -lcurl 
-lSystem 
/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/lib/darwin/libclan
g_rt.osx.a

标签: cmacoscurlgcclibcurl

解决方案


推荐阅读