I am trying to use Protocol Buffers in C++ under Android (x86, x86_64, armeabi-v7a, arm64-v8a). Using these build scripts, I have been able to generate libprotobuf.a static libraries for the different architectures.
However, I am struggling to make the connection between the static libraries and the test_spec.pb.cc and test_spec.pb.h files that I generated with my system's global protobuf compiler of the same version (3.19.2).
What I have tried
- I have tried setting both the
Protobuf_LIBRARYandProtobuf_LIBRARIESto the path tolibprotobuf.a - I have tried setting
Protobuf_INCLUDE_DIRSandProtobuf_INCLUDE_DIRto theincludedirectory I generated running theextract_includes.bat.inscript in protobuf's cmake folder - I have tried finding protobuf using
find_package( Protobuf REQUIRED )andfind_package( Protobuf REQUIRED HINTS _path_to_dir_containing_lib_and_include_) - I have tried setting
Protobuf_SRC_ROOT_FOLDERto a directory containing libprotobuf.a and the include folder
This is my current CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
${CMAKE_PREFIX_PATH}/../cpp
)
ADD_LIBRARY(protobuf STATIC IMPORTED)
SET_TARGET_PROPERTIES(protobuf PROPERTIES IMPORTED_LOCATION ../cpp/libs/${ANDROID_ARCH}/google/protobuf/libprotobuf.a)
INCLUDE(FindProtobuf)
SET(Protobuf_USE_STATIC_LIBS ON)
SET(Protobuf_SRC_ROOT_FOLDER ../cpp)
SET(Protobuf_LIBRARIES protobuf)
SET(Protobuf_INCLUDE_DIR ../cpp/include/google/protobuf)
FIND_PACKAGE(Protobuf REQUIRED)
ADD_LIBRARY(cpp
SHARED
../cpp/rn-etsi-parser.cpp
cpp-adapter.cpp
)
# Specifies a path to native header files.
INCLUDE_DIRECTORIES(
../cpp
)
And this is the current error I get when I run it:
CMake Error at CMakeLists.txt:18 (FIND_PACKAGE):
Could not find a package configuration file provided by "Protobuf" with any
of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
"Protobuf_DIR" to a directory containing one of the above files. If
"Protobuf" provides a separate development package or SDK, be sure it has
been installed.
Thank you for your help!