Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未定义对'的引用;旋度容易初始化';_C++_Linker_Libcurl - Fatal编程技术网

C++ 未定义对'的引用;旋度容易初始化';

C++ 未定义对'的引用;旋度容易初始化';,c++,linker,libcurl,C++,Linker,Libcurl,首先我想说,我看到了类似的帖子,我在上面贴了这篇,但被删除了。。。所以一切都在标题中。我知道这可能是一个问题,在链接器步骤,但我不知道为什么。实际上,我链接了Code::Blocks projet上的所有(*.a)文件,并在链接器选项和搜索目录中添加了curl库的不同路径 我还尝试手动编译和链接,但没有成功 g++ -L ..\lib\curl\lib64 -I ..\lib\curl\include -lcurl main.cpp 又一次尝试 g++ main.cpp -L ..\lib\c

首先我想说,我看到了类似的帖子,我在上面贴了这篇,但被删除了。。。所以一切都在标题中。我知道这可能是一个问题,在链接器步骤,但我不知道为什么。实际上,我链接了Code::Blocks projet上的所有(*.a)文件,并在链接器选项和搜索目录中添加了curl库的不同路径

我还尝试手动编译和链接,但没有成功

g++ -L ..\lib\curl\lib64 -I ..\lib\curl\include -lcurl main.cpp
又一次尝试

g++ main.cpp -L ..\lib\curl\lib64 -I ..\lib\curl\include -lcurl -o test.exe
这就是错误:“对'curl\u easy\u init'的未定义引用”

这是我的代码,可能问题的根源在这里,但我不这么认为(也尝试了静态库)

#包括
#定义CURL\u STATICLIB
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
大小写入数据(void*ptr、大小、大小nmemb、文件*流){
写入的大小=写入(ptr、大小、nmemb、流);
返回已写;}
内部主(空)
{
/*流文件;
myfile.open(“example.txt”);

我的文件,把
main.cpp
放在第一位。它是一样的…伙计们,我真的不知道为什么我不能让它工作,我需要一只外眼,因为我很确定我会做得很好。你能用你尝试过的链接器命令行编辑你的文章吗?g++main.cpp-L..\lib\curl\lib64-I..\lib\curl\include-lcurl-o test.exe,就像你告诉我的那样:),放
main.cpp
首先。它是一样的…伙计们,我真的不知道为什么我不能让它工作,我需要一只外眼,因为我很确定我能做得很好XD你能用你尝试过的链接器命令行编辑你的帖子吗?g++main.cpp-L..\lib\curl\lib64-I..\lib\curl\include-lcurl-o test.exe,就像你告诉我的:)
#include <iostream>
#define CURL_STATICLIB
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include <fstream>
#include <unistd.h>
#include <windows.h>
#include <Lmcons.h>


using namespace std;

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written = fwrite(ptr, size, nmemb, stream);
    return written;}

int main(void)
{

    /*ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
    myfile.close();*/

    CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://stackoverflow.com";
    char outfilename[FILENAME_MAX] = "page.html";
    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        /* always cleanup */
        curl_easy_cleanup(curl);
        fclose(fp);
    }


    return 0;
}