Search code examples
c++visual-studiolinker-errorsstatic-linkingvcpkg

How can I statically link my project dependencies using vcpkg with Visual Studio?


I've read some ways to do what I want but none of them worked and they end up using the same method.

I've tried this solution, which I couldn't make it work...

Here's what I get outputed:

1>libcurl.lib(memdebug.c.obj) : error LNK2001: unresolved external symbol __imp_accept
1>libcurl.lib(memdebug.c.obj) : error LNK2001: unresolved external symbol __imp_closesocket
1>libcurl.lib(memdebug.c.obj) : error LNK2001: unresolved external symbol __imp_recv
1>libcurl.lib(memdebug.c.obj) : error LNK2001: unresolved external symbol __imp_send
1>libcurl.lib(memdebug.c.obj) : error LNK2001: unresolved external symbol __imp_socket
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSACloseEvent
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSACloseEvent
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSACreateEvent
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSACreateEvent
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSAEnumNetworkEvents
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSAEnumNetworkEvents
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSAEventSelect
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSAEventSelect
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSAResetEvent
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetEvent
1>libcurl.lib(multi.c.obj) : error LNK2001: unresolved external symbol __imp_WSAWaitForMultipleEvents
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(asyn-thread.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(sendf.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>libcurl.lib(select.c.obj) : error LNK2001: unresolved external symbol __WSAFDIsSet
1>libcurl.lib(select.c.obj) : error LNK2001: unresolved external symbol __imp_select
1>libcurl.lib(select.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
1>libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_bind
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_bind
1>libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_bind
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_bind
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_connect
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_connect
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_getpeername
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_getpeername
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_getsockname
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_getsockname
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_getsockname
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_getsockopt
1>libcurl.lib(telnet.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(doh.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(socks_sspi.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(hostip.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(smb.c.obj) : error LNK2001: unresolved external symbol __imp_htons
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_ntohs
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_ntohs
1>libcurl.lib(socks_sspi.c.obj) : error LNK2001: unresolved external symbol __imp_ntohs
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
1>libcurl.lib(transfer.c.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
1>libcurl.lib(transfer.c.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
1>libcurl.lib(urlapi.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(connect.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(hostip.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>libcurl.lib(system_win32.c.obj) : error LNK2001: unresolved external symbol __imp_WSAStartup
1>libcurl.lib(system_win32.c.obj) : error LNK2001: unresolved external symbol __imp_WSACleanup
1>libcurl.lib(rand.c.obj) : error LNK2001: unresolved external symbol __imp_ntohl
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CertOpenStore
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertOpenStore
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CertCloseStore
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertCloseStore
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CertEnumCertificatesInStore
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CertFindCertificateInStore
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CertFreeCertificateContext
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertFreeCertificateContext
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_CryptStringToBinaryA
1>libcurl.lib(schannel.c.obj) : error LNK2001: unresolved external symbol __imp_PFXImportCertStore
1>libcurl.lib(ftp.c.obj) : error LNK2001: unresolved external symbol __imp_listen
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_listen
1>libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_recvfrom
1>libcurl.lib(tftp.c.obj) : error LNK2001: unresolved external symbol __imp_sendto
1>libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_getaddrinfo
1>libcurl.lib(curl_addrinfo.c.obj) : error LNK2001: unresolved external symbol __imp_freeaddrinfo
1>libcurl.lib(socketpair.c.obj) : error LNK2001: unresolved external symbol __imp_htonl
1>libcurl.lib(nonblock.c.obj) : error LNK2001: unresolved external symbol __imp_ioctlsocket
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CryptDecodeObjectEx
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertAddCertificateContextToStore
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertFindExtension
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertGetNameStringA
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CryptQueryObject
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertCreateCertificateChainEngine
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertFreeCertificateChainEngine
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertGetCertificateChain
1>libcurl.lib(schannel_verify.c.obj) : error LNK2001: unresolved external symbol __imp_CertFreeCertificateChain
1>libcurl.lib(curl_gethostname.c.obj) : error LNK2001: unresolved external symbol __imp_gethostname
1>C:\Users\pedro\source\repos\vgm\x64\Release\vgm.exe : fatal error LNK1120: 53 unresolved externals

Any thoughts on how to solve this?

Globals part of my .vcxproject:

vcxproject

My Visual Studio's verbosity level (from the solution mentioned): verbosity

Output of vcpkg list: vcpkglist

Type of Runtime Library used: runtimelib

I've found a sort of solution (issue from vcpkg's github) that said I should manually add Ws2_32.Lib, Wldap32.Lib and Crypt32.Lib but I don't know how to do that...

Thank you in advance!


Solution

  • You need to set your lib directory under Configratuon Properties->VC++ Directories to vcpkg static lib directory. On top of that you need to then link the libs under the Configuration Properties->Linker or using pragma comment(lib,"libname")