How to compile a curl static library

Source: Internet
Author: User
Tags ldap

A few days ago, curllib was used in the project, so a source code package was compiled. There were some minor problems in the compilation process. Here, I will share with you the methods for compiling and using this library:

First, go to http://curl.haxx.se/download.html to download the package, because I compiled a zip package under windows.

Step 2: uncompress the zip package. It contains several directories. If you are interested, you can look at other directories. We only use two directories, one is the lib directory, which contains the source code of the library, and the other is the include directory, contains header files provided externally.

Step 3: Use vs2005 to create an empty static library project, add the source code under lib to the project, and add the header file of the Include directory. At this time, the following problems will occur during compilation:

1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (233): warning C4273: "curl_global_init": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1815): see the previous definition of "curl_global_init"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (301): warning C4273: "curl_global_init_mem": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1830): see the previous definition of "curl_global_init_mem"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (330): warning C4273: "curl_global_cleanup": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1845): see the previous definition of "curl_global_cleanup"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (363): warning C4273: "curl_easy_init": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (28): see the previous definition of "curl_easy_init"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (394): warning C4273: "curl_easy_setopt": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (29): see the previous definition of "curl_easy_setopt"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (504): warning C4273: "curl_easy_perform": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (30): see the previous definition of "curl_easy_perform"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (562): warning C4273: "curl_easy_cleanup": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (31): see the previous definition of "curl_easy_cleanup"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (597): warning C4273: "curl_easy_getinfo": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (46): see the previous definition of "curl_easy_getinfo"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ easy. c (614): warning C4273: "curl_easy_duphandle": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (61): see the previous definition of "curl_easy_duphandle"
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ SRC \ easy. C (717): Warning c4273: "curl_easy_reset": inconsistent DLL links
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. H (74): see the previous definition of "curl_easy_reset"
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ SRC \ easy. C (752): Warning c4273: "curl_easy_pause": inconsistent DLL links
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. H (2137): see the previous definition of "curl_easy_pause"
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ SRC \ easy. C (873): Warning c4273: "curl_easy_recv": inconsistent DLL links
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. H (84): see the previous definition of "curl_easy_recv"
1> E: \ c ++ \ curl programming \ curllib7.21.7 \ SRC \ easy. C (901): Warning c4273: "curl_easy_send": inconsistent DLL links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl \ easy. h (95): see the previous definition of "curl_easy_send ".
1> escape. c
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ escape. c (73): warning C4273: "curl_escape": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1771): see the previous definition of "curl_escape"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ escape. c (79): warning C4273: "curl_unescape": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1792): see the previous definition of "curl_unescape"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ escape. c (84): warning C4273: "curl_easy_escape": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1766): see the previous definition of "curl_easy_escape"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ escape. c (145): warning C4273: "curl_easy_unescape": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1786): see the previous definition of "curl_easy_unescape"
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ src \ escape. c (196): warning C4273: "curl_free": inconsistent dll links
1> e: \ c ++ \ curl programming \ curllib7.21.7 \ include \ curl. h (1803): see the previous definition of "curl_free"
Although the compilation is successful, there will be a problem of no link during use.

Fourth, of course, this problem is solved. The cause is that the prototype of the function declaration in the header file is inconsistent with the library settings we want to compile. Although we compile static libraries, however, the function declaration is dynamic,

The solution to this problem is to add the CURL_STATICLIB pre-processing definition to the pre-processing definition in project properties ---- c/c ++ ------- pre-processor. The re-compilation warning is much less.

The generated database can be used.

Fifth, of course, it is to test how to use this library. Let's re-add an empty test project, add the written test source code file to this project, import the static library, and then compile it, the connection still fails. Why? Previously, the pre-defined CURL_STATICLIB must be added to the project properties. After adding and re-compiling, more connection errors will be found,

1> link...
1> curlLib7.21.7.lib (easy. obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ WSACleanup @ 0, which is referenced in function _ win32_init
1> curlLib7.21.7.lib (telnet. obj): error LNK2001: an external symbol that cannot be parsed _ imp _ WSACleanup @ 0
1> curlLib7.21.7.lib (easy. obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ WSAStartup @ 8, which is referenced in function _ win32_init
1> curlLib7.21.7.lib (telnet. obj): error LNK2001: an external symbol that cannot be parsed _ imp _ WSAStartup @ 8
1> curlLib7.21.7.lib (asyn-thread.obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ closesocket @ 4, which is referenced in function _ destroy_async_data
1> curlLib7.21.7.lib (connect. obj): error LNK2001: an external symbol that cannot be parsed _ imp _ closesocket @ 4
1> curlLib7.21.7.lib (select. obj): error LNK2001: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (curl_addrinfo.obj): error LNK2001: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (tftp. obj): error LNK2001: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (telnet. obj): error LNK2001: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (ftp. obj)
: Error LNK2001: external symbols that cannot be parsed _ imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (asyn-thread.obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0. This symbol is used in function _ Curl_resolver_getaddrinfo.
Being referenced
1> curlLib7.21.7.lib (transfer. obj): error LNK2001: external symbol that cannot be parsed _ imp _ WSAGetLastError @ 0
1> curlLib7.21.7.lib (sendf. obj): error LNK2001: external symbols that cannot be parsed
_ Imp _ WSAGetLastError @ 0

.......................................

1> curlLib7.21.7.lib (curl_addrinfo.obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ getservbyport @ 8.
_ WspiapiLegacyGetNameInfo @ 28 is referenced
1> curlLib7.21.7.lib (tftp. obj): error LNK2019: the external symbol _ imp _ sendto @ 24 that cannot be parsed.
_ Tftp_send_first is referenced
1> curlLib7.21.7.lib (tftp. obj): error LNK2019: the external symbol _ imp _ recvfrom @ 24 that cannot be parsed.
_ Tftp_receive_packet is referenced
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_unbind_s that cannot be parsed. This symbol is referenced in function _ Curl_ldap.
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_msgfree, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ber_free that cannot be parsed. This symbol is referenced in function _ Curl_ldap.
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_memfreeW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_value_free_len that cannot be parsed. This symbol is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_get_values_lenW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_next_attributeW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_first_attributeW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_get_dnW that cannot be parsed. This symbol is referenced in function _ Curl_ldap.
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_next_entry, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_first_entry, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_search_sW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_simple_bind_sW that cannot be parsed. This symbol is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_initW that cannot be parsed. This symbol is referenced in function _ Curl_ldap.
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: the external symbol _ imp _ ldap_set_optionW that cannot be parsed. This symbol is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ldap. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ldap_err2stringW, which is referenced in function _ Curl_ldap
1> curlLib7.21.7.lib (ftp. obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ listen @ 8, which is referenced in function _ ftp_state_use_port
1> curlLib7.21.7.lib (ftp. obj): error LNK2019: external symbols that cannot be parsed
_ Imp _ accept @ 12, which is referenced in function _ AllowServerConnect
1> curlLib7.21.7.lib (select. obj): error LNK2019: external symbol that cannot be parsed ___ WSAFDIsSet @ 8, which is in the function
_ Curl_socket_ready is referenced
1> curlLib7.21.7.lib (select. obj): error LNK2019: the external symbol _ imp _ select @ 20 that cannot be parsed.
_ Curl_socket_ready is referenced
1> curlLib7.21.7.lib (nonblock. obj): error LNK2019: external symbol that cannot be parsed _ imp _ ioctlsocket @ 12, which is in the function
_ Curlx_nonblock is referenced
1> curlLib7.21.7.lib (curl_gethostname.obj): error LNK2019: external symbol that cannot be parsed _ imp _ gethostname @ 8, which is in the function
_ Curl_gethostname referenced

However, you will find that these errors are caused by the connection of the culr library to other libraries. Therefore, we need to add two libraries, Ws2_32.lib and Wldap32.lib. After the two libraries are added and compiled, perfect is ready.


Note: When compiling, set the encoding method of the character set. Select the multi-Byte Character Set and set fewer warnings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.