VS2022解决Protobuf compiler version 23.4 doesn‘t match library version 4.23.4
在使用Visual Studio 2022+MinGW+CMake作为开发环境时,如果项目中使用了Protobuf,则在CMake运行时,可能会出现Protobuf compiler version 23.4 doesn't match library version 4.23.4
的问题:
11> [CMake] CMake Warning at C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindProtobuf.cmake:524 (message):
21> [CMake] Protobuf compiler version 23.4 doesn't match library version 4.23.4
可以看到目前VS2022 17.7.1下,CMake的版本还是3.26,而最新版本3.27已经出来了,且MinGW已经是3.27版本了。VS中CMake的FindProtobuf.cmake
模块对Protobuf版本号的查找方式仅适用于Protobuf 22之前的版本,Protobuf 22之后protoc
不再输出主版本号了。
即
1protoc --version
2libprotoc 23.4
没有主版本号4,实际版本号为4.23.4。
只需要把msys64\mingw64\share\cmake\Modules\FindProtobuf.cmake
复制到C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/
目录下,覆盖FindProtobuf.cmake
即可。
另外,在MinGW下使用新版本的Protobuf,还需要链接一系列absl库,最基础的是需要链接absl_log_internal_message
和absl_log_internal_check_op
。
- 原文作者:Witton
- 原文链接:https://wittonbell.github.io/posts/2023/2023-08-21-VS2022解决Protobuf-compiler-version-23.4-doesnt-match-library-version-4.23.4/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。