Visual Studio 2015 curl 不会静态链接 [英] Visual Studio 2015 curl will not statically link

查看:50
本文介绍了Visual Studio 2015 curl 不会静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Visual Studio 2015 静态链接一个小型测试 curl 程序,但是我无法正确链接它.

I am trying to use visual studio 2015 to statically link a small test curl program, however i cannot get it to link properly.

我使用这个批处理文件编译了成功运行的 curl https://github.com/blackrosezy/build-libcurl-windows

I used this batch file to compile curl which worked successfully https://github.com/blackrosezy/build-libcurl-windows

然后我将libcurl目录复制到我的项目目录中,我的代码如下

I then copied the libcurl directory into my project directory and my code is the following

 #include "stdafx.h"
 #include "libcurl/include/curl/curl.h"
 #pragma comment(lib, "libcurl/lib/static-debug-x64/libcurl_a_debug.lib")
 #define CURL_STATICLIB


 int main()
 {
    curl_global_init(CURL_GLOBAL_DEFAULT);
    CURL *curl = curl_easy_init();
    if (curl) {
        CURLcode res;
        curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
    printf("Press any key to continue\n");
    getchar();
    return 0;
 }

但是,无论我做什么,我都无法让我的链接器摆脱这种做法:

However no matter what i do i cannot get my linker to grow out of doing this:

1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_global_init referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_global_cleanup referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function main
1>U:\Main\Code\CurlTest\x64\Debug\CurlTest.exe : fatal error LNK1120: 6 unresolved externals

我已经确认所有这些路径都是有效的,并尝试使用调试库和发布库以及 32 位和 64 位(在 Visual Studio 中使用匹配设置).这将使用非静态库进行编译,但这是废话,因为我只想分发我的 .exe 而不是 dll.

I have confirmed all of these paths are valid, and have tried using both debug and release libs, and 32 and 64 bit (With matching settings in visual studio). This will compile with a non-static library, but that's crap as i'd like to just distribute my .exe not dll's as well.

我在这里做错了什么?这非常令人沮丧,从我从类似线程中读取的内容来看,#define CURL_STATICLIB 指令应该纠正这种行为,这看起来很幼稚.

What am i doing wrong here? This is very frustrating, it looks like it's just being childish as from what i've read from similar threads that #define CURL_STATICLIB directive should rectify this behaviour.

推荐答案

#pragma comment(lib, "wldap32.lib" )
#pragma comment(lib, "crypt32.lib" )
#pragma comment(lib, "Ws2_32.lib")

#define CURL_STATICLIB 
#include <curl/curl.h>

这对我有用.

希望对您有所帮助.

这篇关于Visual Studio 2015 curl 不会静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆