M
M
MasterCopipaster2021-10-11 01:01:31
C++ / C#
MasterCopipaster, 2021-10-11 01:01:31

Build an example C++11 CURL application in MVS2019?

I took an example from the site: https://curl.se/libcurl/c/https.html

Code taken from the site
#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL* curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");

#ifdef SKIP_PEER_VERIFICATION
        /*
         * If you want to connect to a site who isn't using a certificate that is
         * signed by one of the certs in the CA bundle you have, you can skip the
         * verification of the server's certificate. This makes the connection
         * A LOT LESS SECURE.
         *
         * If you have a CA cert for the server stored someplace else than in the
         * default bundle, then the CURLOPT_CAPATH option might come handy for
         * you.
         */
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif

#ifdef SKIP_HOSTNAME_VERIFICATION
        /*
         * If the site you're connecting to uses a different host name that what
         * they have mentioned in their server certificate's commonName (or
         * subjectAltName) fields, libcurl will refuse to connect. You can skip
         * this check, but this will make the connection less secure.
         */
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

        /* always cleanup */
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();

    return 0;
}


Warning C26812 The enum type 'CURLcode' is unscoped. Prefer 'enum class' over 'enum' (Enum.3)
Error LNK2019 unresolved external symbol __imp__curl_global_init referenced in function _main
.... etc.


Moreover, the beard occurs when trying to compile any example with
CURL Of course, I googled, used these instructions and this one. Everywhere the same errors.

All packages installed from VS package manager

curl.7.30.0.2
curl.redist.7.30.0.2
libssh2.1.4.3.1
libssh2.redist.1.4.3.1
openssl.1.0.1.21
openssl.redist.1.0.1.21
 zlib.1.2.8.1
 zlib.redist.1.2.8.1


What else does he need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2021-10-11
@MasterCopipaster

You have problems with linking, import libraries or static libraries are not configured or chosen incorrectly (depending on how you plan to link libcurl to your example project).
It is also possible that the compiler definitions are configured incorrectly - some libraries require preprocessor constants to be set for dynamic, or vice versa, static linking. For example, libcurl requires configuration CURL_STATICLIBfor static linking.

All packages installed from VS package manager

Bury these libraries, the CoApp project, which was dedicated to the idea of ​​using NuGet for native (C / C ++) libraries, died almost immediately after its birth, at the border of 2014/2015. These are very old versions, besides. Practice has shown that NuGet is in most cases not suitable for native libraries (I will not describe why).
Use normal package managers like Conan or, at worst, Vcpkg for C/C++ projects . It's all there already . However, this does not eliminate the need to understand the simplest errors of the compiler / linker and its main options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question