Vcpkg: Failed to use static libraries: LNK2001

Created on 21 Jan 2018  路  2Comments  路  Source: microsoft/vcpkg

My machine setup:

  • Windows 10.0.16299.125
  • MSVC 19.12.25834

When I tried to build a c file like this

#include <curl\curl.h>
int main()
{
    CURL *pCURL = curl_easy_init();
    return 0;
}

I want to link this program to static libcurl, so I executed vcpkg install curl:x64-windows-static, which finished successfully.
Then I installed the nuget package from vcpkg integrate project and modified the vcxproj by these steps.
vcxproj platform is x64 and RuntimeLibrary is MultiThreadedDebug/MultiThreaded.
I tried to compile it but only found Linker Tools Error LNK2001.
The error log is listed below:

libcurl.lib(easy.c.obj) : error LNK2019: unresolved external symbol __imp_WSAStartup referenced in function win32_init
libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSAStartup
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_WSAStartup
libcurl.lib(easy.c.obj) : error LNK2019: unresolved external symbol __imp_WSACleanup referenced in function win32_cleanup
libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSACleanup
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_WSACleanup
libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(openssl.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(hostcheck.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(cookie.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(asyn-thread.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(url.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
libssh2.lib(misc.obj) : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function _libssh2_base64_encode
libeay32.lib(bss_sock.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(openssl.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(asyn-thread.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(select.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(sendf.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
libcurl.lib(select.c.obj) : error LNK2019: unresolved external symbol __WSAFDIsSet referenced in function Curl_socket_check
libssh2.lib(session.obj) : error LNK2001: unresolved external symbol __WSAFDIsSet
libcurl.lib(select.c.obj) : error LNK2019: unresolved external symbol __imp_select referenced in function Curl_socket_check
libssh2.lib(session.obj) : error LNK2001: unresolved external symbol __imp_select
libeay32.lib(bss_conn.obj) : error LNK2019: unresolved external symbol __imp_WSASetLastError referenced in function conn_state
libcurl.lib(select.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
libeay32.lib(bss_sock.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_bind referenced in function bindlocal
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_bind
libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_bind
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_bind
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_connect referenced in function singleipconnect
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_connect
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_connect
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_getpeername referenced in function Curl_updateconninfo
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_getsockname referenced in function Curl_updateconninfo
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_getsockname
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_getsockopt referenced in function Curl_sndbufset
libssh2.lib(session.obj) : error LNK2001: unresolved external symbol __imp_getsockopt
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_getsockopt
libcurl.lib(smb.c.obj) : error LNK2019: unresolved external symbol __imp_htons referenced in function smb_request_state
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_htons
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_htons
libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_htons
libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_htons
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_htons
libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_htons
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_ntohs referenced in function bindlocal
libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_ntohs
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_ntohs
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_setsockopt referenced in function Curl_sndbufset
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
libcurl.lib(connect.c.obj) : error LNK2019: unresolved external symbol __imp_WSAIoctl referenced in function tcpkeepalive
libcurl.lib(memdebug.c.obj) : error LNK2019: unresolved external symbol __imp_accept referenced in function curl_accept
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_accept
libcurl.lib(memdebug.c.obj) : error LNK2019: unresolved external symbol __imp_closesocket referenced in function curl_sclose
libeay32.lib(bss_sock.obj) : error LNK2001: unresolved external symbol __imp_closesocket
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_closesocket
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_closesocket
libcurl.lib(memdebug.c.obj) : error LNK2019: unresolved external symbol __imp_recv referenced in function curl_dorecv
libssh2.lib(misc.obj) : error LNK2001: unresolved external symbol __imp_recv
libeay32.lib(bss_sock.obj) : error LNK2001: unresolved external symbol __imp_recv
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_recv
libcurl.lib(memdebug.c.obj) : error LNK2019: unresolved external symbol __imp_send referenced in function curl_dosend
libssh2.lib(misc.obj) : error LNK2001: unresolved external symbol __imp_send
libeay32.lib(bss_sock.obj) : error LNK2001: unresolved external symbol __imp_send
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_send
libcurl.lib(memdebug.c.obj) : error LNK2019: unresolved external symbol __imp_socket referenced in function curl_socket
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_socket
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_socket
libcurl.lib(curl_addrinfo.c.obj) : error LNK2019: unresolved external symbol __imp_getaddrinfo referenced in function curl_dogetaddrinfo
libcurl.lib(curl_addrinfo.c.obj) : error LNK2019: unresolved external symbol __imp_freeaddrinfo referenced in function curl_dofreeaddrinfo
libcurl.lib(ftp.c.obj) : error LNK2019: unresolved external symbol __imp_listen referenced in function ftp_state_use_port
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_listen
libcurl.lib(tftp.c.obj) : error LNK2019: unresolved external symbol __imp_recvfrom referenced in function tftp_receive_packet
libcurl.lib(tftp.c.obj) : error LNK2019: unresolved external symbol __imp_sendto referenced in function tftp_rx
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_init referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_unbind_s referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_set_option referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_simple_bind_s referenced in function ldap_win_bind
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_search_s referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_msgfree referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_err2string referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_first_entry referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_next_entry referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_first_attribute referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_next_attribute referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_get_values_len referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_value_free_len referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_get_dn referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ldap_memfree referenced in function _ldap_free_urldesc
libcurl.lib(ldap.c.obj) : error LNK2019: unresolved external symbol __imp_ber_free referenced in function _ldap_free_urldesc
libcurl.lib(nonblock.c.obj) : error LNK2019: unresolved external symbol __imp_ioctlsocket referenced in function curlx_nonblock
libssh2.lib(session.obj) : error LNK2001: unresolved external symbol __imp_ioctlsocket
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_ioctlsocket
libcurl.lib(curl_gethostname.c.obj) : error LNK2019: unresolved external symbol __imp_gethostname referenced in function Curl_gethostname
libcurl.lib(rand.c.obj) : error LNK2019: unresolved external symbol __imp_ntohl referenced in function randit
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_ntohl
libeay32.lib(bss_sock.obj) : error LNK2019: unresolved external symbol __imp_shutdown referenced in function sock_free
libeay32.lib(bss_conn.obj) : error LNK2001: unresolved external symbol __imp_shutdown
libeay32.lib(bss_conn.obj) : error LNK2019: unresolved external symbol __imp_htonl referenced in function conn_state
libeay32.lib(b_sock.obj) : error LNK2001: unresolved external symbol __imp_htonl
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertOpenStore referenced in function capi_open_store
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertCloseStore referenced in function capi_find_key
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertEnumCertificatesInStore referenced in function capi_find_cert
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertFindCertificateInStore referenced in function capi_find_cert
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertDuplicateCertificateContext referenced in function capi_load_ssl_client_cert
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertFreeCertificateContext referenced in function capi_find_key
libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertGetCertificateContextProperty referenced in function capi_cert_get_fname
libeay32.lib(b_sock.obj) : error LNK2019: unresolved external symbol __imp_gethostbyname referenced in function BIO_gethostbyname
libeay32.lib(b_sock.obj) : error LNK2019: unresolved external symbol __imp_getservbyname referenced in function BIO_get_port

Most helpful comment

Thank you for your reply, but unfortunately there is no winsocks2.lib in Windows SDK.
But your direction is right. I found Ws2_32.Lib as an alternative.
After added this to the linker, the number of problems was reduced to 24.
In fact, it needs another two librarys: Wldap32.Lib and Crypt32.Lib.
Only when these three libraries are included in the project, this simple c file can be statically compiled.

All 2 comments

You will also need to link winsock2.lib manually, from the windows SDK.

Thank you for your reply, but unfortunately there is no winsocks2.lib in Windows SDK.
But your direction is right. I found Ws2_32.Lib as an alternative.
After added this to the linker, the number of problems was reduced to 24.
In fact, it needs another two librarys: Wldap32.Lib and Crypt32.Lib.
Only when these three libraries are included in the project, this simple c file can be statically compiled.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjvaijo picture cjvaijo  路  3Comments

spindensity picture spindensity  路  3Comments

ghost picture ghost  路  3Comments

oahzuw picture oahzuw  路  3Comments

ThinkalVB picture ThinkalVB  路  3Comments