【问题标题】:Building protobuf 3.9.4 on windows with cmake使用 cmake 在 windows 上构建 protobuf 3.9.4
【发布时间】:2017-11-04 07:06:28
【问题描述】:

我正在尝试使用 cmake 在 Windows 上构建 protobuf 3.9.4,但是当我单击“配置”时,我收到一条消息说“链接:致命错误 LNK1101:不正确的 MSPDB140.DLL 版本;重新检查此产品的安装”。

有人知道这里发生了什么吗?

Visual Studio 很可能有问题,但我不确定是什么问题。

我尝试在谷歌上搜索解决方案,但没有一个与我的问题有关。

附: 我正在使用 cmake 的 gui 版本。

【问题讨论】:

  • Something's wrong with Visual Studio, most likely - 是的。这很可能与 CMake 和 protobuf 都无关

标签: visual-studio cmake protocol-buffers


【解决方案1】:

有一个有用的 CMake 脚本修补示例,需要使用 vcpkg 使用 Visual Studio 2017 构建 protobuf 3.4.1。

#region PDFsharp - A .NET library for processing PDF
//
// Authors:
//   Stefan Lange
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 7618ba2..d282a60 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -165,8 +165,10 @@ endif (protobuf_UNICODE)

 include(libprotobuf-lite.cmake)
 include(libprotobuf.cmake)
-include(libprotoc.cmake)
-include(protoc.cmake)
+if(protobuf_BUILD_COMPILER)
+  include(libprotoc.cmake)
+  include(protoc.cmake)
+endif()

 if (protobuf_BUILD_TESTS)
   include(tests.cmake)

diff --git a/cmake/install.cmake b/cmake/install.cmake
index 441bf55..20b3aa0 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -1,14 +1,17 @@
 include(GNUInstallDirs)

+set(LIBRARIES_TO_SET_DEST libprotobuf-lite libprotobuf)
+if(protobuf_BUILD_COMPILER)
+  list(APPEND LIBRARIES_TO_SET_DEST libprotoc)
+endif()
+
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake
                ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake
                ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY)

 foreach(_library
-  libprotobuf-lite
-  libprotobuf
-  libprotoc)
+  ${LIBRARIES_TO_SET_DEST})
   set_property(TARGET ${_library}
     PROPERTY INTERFACE_INCLUDE_DIRECTORIES
     $<BUILD_INTERFACE:${protobuf_source_dir}/src>
@@ -19,8 +22,10 @@ foreach(_library
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
 endforeach()

-install(TARGETS protoc EXPORT protobuf-targets
-  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+if(protobuf_BUILD_COMPILER)
+  install(TARGETS protoc EXPORT protobuf-targets
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+endif()

 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

@@ -101,7 +106,12 @@ configure_file(protobuf-options.cmake
   ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)

 # Allows the build directory to be used as a find directory.
-export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
+set(FIND_DIRS libprotobuf-lite libprotobuf)
+if(protobuf_BUILD_COMPILER)
+  list(APPEND FIND_DIRS libprotoc protoc)
+endif()
+
+export(TARGETS ${FIND_DIRS}
   NAMESPACE protobuf::
   FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
 )

获得 3.9.4 版本最简单的方法是升级原始 protobuf 3.4.1 vcpkg port。到目前为止,我使用 vcpkg 构建 C/C++ 端口的经验是积极的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2018-03-15
    • 2021-11-15
    • 2021-11-27
    • 2021-10-02
    • 2020-08-12
    相关资源
    最近更新 更多