I鈥檓 trying to use vcpkg and build the sdk as static. Vcpkg returns with no errors but when I go to build my project in visual studio I get linker errors. My vcpkg command is
vcpkg install aws-sdk-cpp[core,polly,text-to-service]:x64-windows-static
The error is LNK2001 and it comes from core.
Hi @hansob3, have you looked at the vcpkg docs[1] for MSBuild integration and how to select your triplet?
You will need to add an MSBuild property to indicate that you want to use static binaries.
[1] https://github.com/Microsoft/vcpkg/blob/master/docs/users/integration.md#triplet-selection
I did see that and copied that into my .vcxproj just as they have it.
Could you please post a short source snippet that causes the problem and also post the linker error in full?
Here is the output from the build. For a code snippet I am just using the polly example as is. I created a new console project then just copied the code in from main. In the project settings I changed to /MT
1>aws-cpp-sdk-core.lib(Net.cpp.obj) : error LNK2001: unresolved external symbol __imp_WSAStartup
1>aws-cpp-sdk-core.lib(Net.cpp.obj) : error LNK2001: unresolved external symbol __imp_WSACleanup
1>aws-cpp-sdk-core.lib(FileSystem.cpp.obj) : error LNK2001: unresolved external symbol __imp_GetUserProfileDirectoryW
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol GetFileVersionInfoSizeA
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol GetFileVersionInfoA
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol VerQueryValueA
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_bind
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_closesocket
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_connect
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_ioctlsocket
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_htons
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_recv
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_recvfrom
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_send
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_sendto
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_socket
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
1>aws-cpp-sdk-core.lib(SimpleUDP.cpp.obj) : error LNK2001: unresolved external symbol __imp_inet_pton
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptOpenAlgorithmProvider
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptGetProperty
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptSetProperty
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptCloseAlgorithmProvider
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptEncrypt
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptDecrypt
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptExportKey
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptImportKey
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptDestroyKey
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptCreateHash
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptHashData
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptFinishHash
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptDestroyHash
1>aws-cpp-sdk-core.lib(CryptoImpl.cpp.obj) : error LNK2001: unresolved external symbol BCryptGenRandom
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetOpenA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetCloseHandle
1>aws-cpp-sdk-core.lib(WinINetConnectionPoolMgr.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetCloseHandle
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetReadFile
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetWriteFile
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetSetOptionA
1>aws-cpp-sdk-core.lib(WinINetConnectionPoolMgr.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetSetOptionA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_HttpOpenRequestA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_HttpAddRequestHeadersA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_HttpSendRequestExA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_HttpEndRequestA
1>aws-cpp-sdk-core.lib(WinINetSyncHttpClient.cpp.obj) : error LNK2001: unresolved external symbol __imp_HttpQueryInfoA
1>aws-cpp-sdk-core.lib(WinINetConnectionPoolMgr.cpp.obj) : error LNK2001: unresolved external symbol __imp_InternetConnectA
Thanks. You'll need to add some more libraries to your link line explicitly:
userenv.lib [1]ws2_32.lib [2]Wininet.lib [3]bcrypt.lib [4][1] https://docs.microsoft.com/en-us/windows/desktop/api/userenv/nf-userenv-getuserprofiledirectoryw
[2] https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsacleanup
[3] https://docs.microsoft.com/en-us/windows/desktop/api/wininet/nf-wininet-httpaddrequestheadersa
[4] https://docs.microsoft.com/en-us/windows/desktop/api/bcrypt/nf-bcrypt-bcryptgenrandom
I added those but I am still left with these:
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol GetFileVersionInfoSizeA
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol GetFileVersionInfoA
1>aws-cpp-sdk-core.lib(OSVersionInfo.cpp.obj) : error LNK2001: unresolved external symbol VerQueryValueA
I went to the Microsoft Docs and tried adding Mincore.lib as well but I am still getting these errors.
Also found that I needed to add version.lib. Once that was added the build succeeded. I read about it here.
Most helpful comment
Thanks. You'll need to add some more libraries to your link line explicitly:
userenv.lib[1]ws2_32.lib[2]Wininet.lib[3]bcrypt.lib[4][1] https://docs.microsoft.com/en-us/windows/desktop/api/userenv/nf-userenv-getuserprofiledirectoryw
[2] https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsacleanup
[3] https://docs.microsoft.com/en-us/windows/desktop/api/wininet/nf-wininet-httpaddrequestheadersa
[4] https://docs.microsoft.com/en-us/windows/desktop/api/bcrypt/nf-bcrypt-bcryptgenrandom