无法使用 libcurl 库编译 C++ 程序

Can not compile c++ program with libcurl library

我正在使用编译器 MinGW64 和 Clion 开发人员。

我做了什么:

1) 从“https://curl.haxx.se/download.html

下载了 curl-7.64.0.tar.gz

2) 通过cmd编译库-->curl-7.64.0 root-->'mingw32-make make'

3) 成功后,我将 headers 放入我的 MinGW 的 include 文件夹中, libcurl.a andlibcurldll.a 放入我的 MinGW 的 lib 文件夹中。

4) 然后我尝试使用在 Clion 中设置 CMake 的简单 libcurl 代码,如下所示:

cmake_minimum_required(VERSION 3.12)
add_executable(test main.cpp)
target_link_libraries(test libcurl.a libcurldll.a)

我的 main.cpp 代码是这样的:

#include <curl/curl.h>
#include <string>

int main()
{
    auto curl = curl_easy_init();
}

当我编译它时出现错误 'Process finished with exit code -1073741515 (0xC0000135)'。

谁能告诉我哪里出了问题?

您必须将 -lcurl 放入 mingw 参数列表中。

你这样做过吗:

Make sure that MinGW32's bin dir is in the search path, for example:

set PATH=c:\mingw32\bin;%PATH%

then run mingw32-make mingw32 in the root dir. There are other make targets available to build libcurl with more features, use:

mingw32-make mingw32-zlib to build with Zlib support;
mingw32-make mingw32-ssl-zlib to build with SSL and Zlib enabled;
mingw32-make mingw32-ssh2-ssl-zlib to build with SSH2, SSL, Zlib;
mingw32-make mingw32-ssh2-ssl-sspi-zlib to build with SSH2, SSL, Zlib and SSPI support.

If you have any problems linking libraries or finding header files, be sure to verify that the provided "Makefile.m32" files use the proper paths, and adjust as necessary. It is also possible to override these paths with environment variables, for example:

set ZLIB_PATH=c:\zlib-1.2.8
set OPENSSL_PATH=c:\openssl-1.0.2c
set LIBSSH2_PATH=c:\libssh2-1.6.0

It is also possible to build with other LDAP SDKs than MS LDAP; currently it is possible to build with native Win32 OpenLDAP, or with the Novell CLDAP SDK. If you want to use these you need to set these vars:

set LDAP_SDK=c:\openldap
set USE_LDAP_OPENLDAP=1

or for using the Novell SDK:

set USE_LDAP_NOVELL=1

If you want to enable LDAPS support then set LDAPS=1

https://curl.haxx.se/docs/install.html