我下载的是
protobuf-27.4
以下使用vs2022
根据readme,执行如下命令
"C:\Program Files\CMake\bin\cmake.exe" -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=C:\Users\x\Downloads\install C:\Users\x\Downloads\protobuf-27.4 -Dprotobuf_BUILD_TESTS=OFF
他会报错说absl找不到,需要从网上下载一下absl的源码
abseil-cpp-20240722.0.zip
下载完之后,把压缩包里面的东西全部拖进C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp目录里面
然后重新执行上面那个命令
生成一个sln文件,打开之后,生成libprotobufd.lib文件
这里注意调整生成选项,要和你使用protobuf的项目的选项保持一致
同时需要把下图中划线的项目生成一下,生成选项也要保持一致
下面需要对测试项目进行配置
首先就是include目录,如下:
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp
C:\Users\x\Downloads\protobuf-27.4\src
然后是linkrt选项的input
C:\Users\x\Downloads\protobuf-27.4\Debug\libprotobufd.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\types\Debug\absl_bad_any_cast_impl.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\types\Debug\absl_bad_optional_access.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\types\Debug\absl_bad_variant_access.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_base.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\hash\Debug\absl_city.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\time\Debug\absl_civil_time.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cord.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cord_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cordz_functions.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cordz_handle.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cordz_info.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_cordz_sample_token.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\crc\Debug\absl_crc32c.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\crc\Debug\absl_crc_cord_state.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\crc\Debug\absl_crc_cpu_detect.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\crc\Debug\absl_crc_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_debugging_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_decode_rust_punycode.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_demangle_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_demangle_rust.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_die_if_null.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_examine_stack.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\profiling\Debug\absl_exponential_biased.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_failure_signal_handler.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_commandlineflag.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_commandlineflag_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_config.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_marshalling.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_parse.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_private_handle_accessor.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_program_name.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_reflection.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_usage.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\flags\Debug\absl_flags_usage_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\synchronization\Debug\absl_graphcycles_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\hash\Debug\absl_hash.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\container\Debug\absl_hashtablez_sampler.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\numeric\Debug\absl_int128.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\synchronization\Debug\absl_kernel_timeout_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_leak_check.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_entry.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_flags.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_globals.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_initialize.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_check_op.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_conditions.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_fnmatch.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_format.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_globals.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_log_sink_set.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_message.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_nullguard.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_internal_proto.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_log_severity.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_log_sink.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\hash\Debug\absl_low_level_hash.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_malloc_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\profiling\Debug\absl_periodic_sampler.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_poison.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_distributions.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_distribution_test_util.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_platform.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_pool_urbg.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_randen.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_randen_hwaes.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_randen_hwaes_impl.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_randen_slow.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_internal_seed_material.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_seed_gen_exception.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\random\Debug\absl_random_seed_sequences.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\container\Debug\absl_raw_hash_set.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_raw_logging_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_scoped_set_env.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_spinlock_wait.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_stacktrace.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\status\Debug\absl_status.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\status\Debug\absl_statusor.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_str_format_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_strerror.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_string_view.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_strings.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\strings\Debug\absl_strings_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_symbolize.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\synchronization\Debug\absl_synchronization.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\base\Debug\absl_throw_delegate.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\time\Debug\absl_time.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\time\Debug\absl_time_zone.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\debugging\Debug\absl_utf8_for_code_point.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\abseil-cpp\absl\log\Debug\absl_vlog_config_internal.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\utf8_range\Debug\utf8_range.lib
C:\Users\x\Downloads\protobuf-27.4\third_party\utf8_range\Debug\utf8_validity.lib
这样就可以了