From 18fae1c15112efad2080c2b2f726d904fea48b35 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sun, 7 May 2023 09:22:27 -0700 Subject: [PATCH] fix: missing -DPROTOBUF_USE_DLLS in pkg-config (#12700) When the protobuf libraries have been compiled as shared libraries the users of the library need to add `-DPROTOBUF_USE_DLLS` to their build line. Otherwise some symbols are missing. Fixes #12699 FWIW, I am not sure this is an ideal fix. It may be better to fix the headers such that no macros change the ABI. Closes #12700 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12700 from coryan:fix-define-protobuf-use-dlls-in-pkg-config-file 13c792eebd3d070fa25eff68cfca6ae1493e9503 PiperOrigin-RevId: 530116678 --- cmake/install.cmake | 4 ++++ cmake/protobuf-lite.pc.cmake | 2 +- cmake/protobuf.pc.cmake | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 9d837ac536c9..8c96981da8b3 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -12,6 +12,10 @@ foreach (_target IN LISTS _pc_target_list) string(CONCAT _protobuf_PC_REQUIRES "${_protobuf_PC_REQUIRES}" "${_sep}" "${_target}") set(_sep " ") endforeach () +set(_protobuf_PC_CFLAGS) +if (protobuf_BUILD_SHARED_LIBS) + set(_protobuf_PC_CFLAGS -DPROTOBUF_USE_DLLS) +endif () configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) diff --git a/cmake/protobuf-lite.pc.cmake b/cmake/protobuf-lite.pc.cmake index 7f88046998ea..47d911b303fa 100644 --- a/cmake/protobuf-lite.pc.cmake +++ b/cmake/protobuf-lite.pc.cmake @@ -9,5 +9,5 @@ Version: @protobuf_VERSION@ Requires: @_protobuf_PC_REQUIRES@ Requires.private: @_protobuf_PC_REQUIRES_PRIVATE@ Libs: -L${libdir} -lprotobuf-lite @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} +Cflags: -I${includedir} @_protobuf_PC_CFLAGS@ Conflicts: protobuf diff --git a/cmake/protobuf.pc.cmake b/cmake/protobuf.pc.cmake index b3cda920757c..8f6b78c28c64 100644 --- a/cmake/protobuf.pc.cmake +++ b/cmake/protobuf.pc.cmake @@ -9,5 +9,5 @@ Version: @protobuf_VERSION@ Requires: @_protobuf_PC_REQUIRES@ Requires.private: @_protobuf_PC_REQUIRES_PRIVATE@ Libs: -L${libdir} -lprotobuf @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} +Cflags: -I${includedir} @_protobuf_PC_CFLAGS@ Conflicts: protobuf-lite