Describe the bug
A build for a project which depends on grpc fails due to link errors.
Environment
To Reproduce
Steps to reproduce the behavior:
using namespace grpc;
std::string server_address("127.0.0.1:8081");
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
Expected behavior
No Error.
Failure logs
1>grpc.lib(jwt_credentials.cc.obj) : error LNK2019: 未解決の外部シンボル ___dyn_tls_on_demand_init が関数 "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@$$QAV01@@Z) で参照されました。
1>grpc.lib(alts_tsi_handshaker.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(alts_zero_copy_grpc_protector.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(alts_grpc_record_protocol_common.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(google_default_credentials.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(tcp_server_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(tcp_client_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(oauth2_credentials.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(pollset_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(resolve_address_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(tcp_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(timer_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(resolve_address_windows.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(channel_create.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(secure_channel_create.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(grpc_ares_ev_driver.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(stream_compression_gzip.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(frame_ping.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(iocp_windows.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(pollset_windows.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(security_context.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(xds_client.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(iomgr_custom.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(health_check_client.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(hpack_encoder.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(hpack_parser.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(writing.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(parsing.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(subchannel.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(backup_poller.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(bdp_estimator.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(flow_control.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(client_idle_filter.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(max_age_filter.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(status_conversion.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(backoff.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(grpclb.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(xds.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(dns_resolver_ares.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(dns_resolver.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(chttp2_transport.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(timer_generic.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(credentials.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(server_auth_filter.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(iomgr.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(timer_manager.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(lame_client.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(client_channel.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(channelz.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(stats_data.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(stats.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(combiner.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(chttp2_server.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(call_combiner.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(transport.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(channel_trace.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(byte_buffer_reader.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(slice_buffer.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(channel_connectivity.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(channel.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(completion_queue.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(call.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(inproc_transport.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(executor.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(slice.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(byte_buffer.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(call_details.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(init.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(server_chttp2.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(server.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(resource_quota.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(exec_ctx.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc++.lib(channel_arguments.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc++.lib(server_cc.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc++.lib(server_callback.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc++.lib(thread_manager.cc.obj) : error LNK2001: 外部シンボル "___dyn_tls_on_demand_init" は未解決です。
1>grpc.lib(jwt_credentials.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(alts_tsi_handshaker.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(alts_zero_copy_grpc_protector.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(alts_grpc_record_protocol_common.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(google_default_credentials.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(tcp_server_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(tcp_client_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(oauth2_credentials.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(pollset_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(resolve_address_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(tcp_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(timer_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(resolve_address_windows.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(channel_create.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(secure_channel_create.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(grpc_ares_ev_driver.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(stream_compression_gzip.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(frame_ping.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(iocp_windows.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(pollset_windows.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(security_context.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(xds_client.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(iomgr_custom.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(health_check_client.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(hpack_encoder.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(hpack_parser.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(writing.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(parsing.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(subchannel.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(backup_poller.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(bdp_estimator.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(flow_control.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(client_idle_filter.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(max_age_filter.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(status_conversion.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(backoff.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(grpclb.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(xds.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(dns_resolver_ares.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(dns_resolver.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(chttp2_transport.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(timer_generic.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(credentials.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(server_auth_filter.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(iomgr.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(timer_manager.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(lame_client.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(client_channel.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(channelz.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(stats_data.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(stats.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(combiner.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(chttp2_server.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(call_combiner.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(transport.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(channel_trace.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(byte_buffer_reader.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(slice_buffer.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(channel_connectivity.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(channel.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(completion_queue.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(call.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(inproc_transport.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(executor.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(slice.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(byte_buffer.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(call_details.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(init.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(server_chttp2.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(server.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(resource_quota.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc.lib(exec_ctx.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc++.lib(channel_arguments.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc++.lib(server_cc.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc++.lib(server_callback.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
1>grpc++.lib(thread_manager.cc.obj) : error LNK2001: 外部シンボル "___tls_guard" は未解決です。
Additional context
It turns out that ___tls_guard and ___dyn_tls_on_demand_init are from VS2019.
https://developercommunity.visualstudio.com/content/problem/1010557/-dyn-tls-on-demand-init-and-tls-guard-related-weir.html
It seems that vcpkg runs build with the VS2019 compiler even if I have run "./vcpkg install grpc" on VS2017 developer console.
On Developer Command Prompt for VS2017, the following commands worked.
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
SET VCPKG_VISUAL_STUDIO_PATH=%VSINSTALLDIR:~0,-1%
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg install grpc
Hi @nakag2020, sorry for late.
We strongly recommend to use Powershell instead of cmd or Developer Command Prompt.
Please use powershell and try again.
Thanks.
I've got the same problem when building/using Abseil. I'm using Visual Studio 2017 to build my executable (and no, I'm not upgrading any time soon), so as vcpkg chose to use my newest Visual Studio installation (2019), I'm coming across the same error as @nakag2020.
So, following @JackBoosY's comment above, I rebuilt within a Powershell session and (unsurprisingly), vcpkg was still using Visual Studio 2019 to build vcpkg libraries, so that build of the library also caused the same errors.
Using @nakag2020's workaround (setting VCPKG_VISUAL_STUDIO_PATH to point at the Visual Studio 2017 install directory) built abseil with VS2017, as I wanted, so there's that.
The other thing I tried was creating a new triplet file that set the CMake variable VCPKG_PLATFORM_TOOLSET to 'v141', as documented here. This also built the library with Visual Studio 2017, as I needed.
For me, creating (and using) triplets that specify the Visual Studio version is probably the workaround I'll use, as it doesn't require me to first remember, and then perform, some manual step every time I use vcpkg (aside from specifying the custom triplet).
Switching between Visual Studio versions on the command-line is a pain. I also develop on Linux and at least there, I can refer to gcc-8 or gcc-9, and use update-alternatives to choose my default version of gcc (which will then be respected by vcpkg). It would be nice if switching versions was handled as gracefully by Visual Studio...
@studoot Yes, when multiple versions of Visual Studio are installed on the machine, vcpkg will use the latest version of Visual Studio by default.
If you want to use a earlier version of Visual Studio, please modify _VCPKG_PATH/triplets/*.cmake_ and add the following code to it (eg: Visual Studio 2017-v141):
set(VCPKG_PLATFORM_TOOLSET v141)
@JackBoosY The trouble is that this has to be done on a per-triplet basis rather than being a global default.
Let me illustrate the problem with my typical working scenario... I use a mix of mostly VS2017 & some VS2019, from the command-line (I use VS Code mostly). My understanding is that, thanks to the binary compatibility introduced in VS2015, I should be able build all my vcpkg libraries with VS2017 and then use them with either VS2017 or VS2019 (because my final binary would always be linking with a runtime at least as new as the one used to build the libraries).
However, the default toolchain strategy used by vcpkg makes this harder to do than it should be. If I follow your suggestion, then I end up with a vcpkg Git repository that is always one (or more) commits different than HEAD on origin. I guess a git pull --rebase rather than just a simple git pull will always fix that up, but it's messy. I don't know what a fully satisfactory answer to this question is, but I haven't seen one yet.
@vicroms Could you please take a look?
Thanks.
I should be able build all my vcpkg libraries with VS2017 and then use them with either VS2017 or VS2019
That is correct, but vcpkg by default will use the latest version you have installed. The binary compatibility constraint requires that you use a linker and support .libs newer than the highest version of all the link inputs.
I believe you can get this to work by setting VCPKG_PLATFORM_TOOLSET to v141 (as described in https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md#vcpkg_platform_toolset ) but have not tried that myself...
vcpkg by default will use the latest version you have installed
And that's the default that I'd like to be able to change somehow, while still using the stock triplets (i.e. not using the VCPKG_PLATFORM_TOOLSET triplet file property).
On the other hand, triplets specifying toolset versions are probably an easier way forward.
Trouble is, the confusion of versions will still exist. Oh well.
Triplets are the solution we have built for this problem; if you are running into this in a CI scenario or similar we have overlay triplets so that you don't need to edit the tree itself; I suspect any command line interface we could add would be more annoying than that.
overlay triplets
That was part of the puzzle that I'd missed. So, I can create a directory in my project that contains version specific triplets & overlay that directory when building & exporting the ports for my project (which I already have a script for).
OK - I can live with that.
We hope your question was answered to your satisfaction; if it wasn't, you can reopen with more info.
Most helpful comment
I've got the same problem when building/using Abseil. I'm using Visual Studio 2017 to build my executable (and no, I'm not upgrading any time soon), so as vcpkg chose to use my newest Visual Studio installation (2019), I'm coming across the same error as @nakag2020.
So, following @JackBoosY's comment above, I rebuilt within a Powershell session and (unsurprisingly), vcpkg was still using Visual Studio 2019 to build vcpkg libraries, so that build of the library also caused the same errors.
Using @nakag2020's workaround (setting
VCPKG_VISUAL_STUDIO_PATHto point at the Visual Studio 2017 install directory) built abseil with VS2017, as I wanted, so there's that.The other thing I tried was creating a new triplet file that set the CMake variable
VCPKG_PLATFORM_TOOLSETto 'v141', as documented here. This also built the library with Visual Studio 2017, as I needed.For me, creating (and using) triplets that specify the Visual Studio version is probably the workaround I'll use, as it doesn't require me to first remember, and then perform, some manual step every time I use vcpkg (aside from specifying the custom triplet).
Switching between Visual Studio versions on the command-line is a pain. I also develop on Linux and at least there, I can refer to gcc-8 or gcc-9, and use
update-alternativesto choose my default version of gcc (which will then be respected by vcpkg). It would be nice if switching versions was handled as gracefully by Visual Studio...