android– 使用独立NDK工具链构建协议缓冲区

android– 使用独立NDK工具链构建协议缓冲区,第1张

概述我在使用使用$NDK/build/tools/make-standalone-toolchain.sh脚本创建的独立NDK工具链构建适用于Android的ProtocolBuffers时遇到问题.我遇到的问题是:libtool:link:g++-Wall-Wwrite-strings-Woverloaded-virtual-Wno-sign-compare-O2-g-DNDEBUG-oprotocmain.o

我在使用使用$NDK / build / tools / make-standalone-toolchain.sh脚本创建的独立NDK工具链构建适用于Android的Protocol Buffers时遇到问题.我遇到的问题是:

libtool: link: g++ -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -o protoc main.o  ./.libs/libprotobuf.a ./.libs/libprotoc.a /home/sizeak/AudioFingerprinting/ProtoBuf/jni/src/.libs/libprotobuf.a -lz -lc./.libs/libprotoc.a(plugin.pb.o): In function `GoogleOnceInit':/home/sizeak/AudioFingerprinting/ProtoBuf/jni/src/./Google/protobuf/stubs/once.h:115: undefined reference to `pthread_once'

这似乎意味着缺少pthreads库,但是sysroot是由ndk脚本创建的,所以应该包含所有内容,对吧?我在某处读到,在使用独立工具链时没有必要显式链接pthreads.我使用的configure命令是:

./configure --host=arm-eabi --with-sysroot=$SYSROOT CC=$CC --enable-cross-compile --with-protoc=protoc liBS="-lc"

将环境变量设置为指向脚本创建的sysroot的位置.

我在网上的很多页面上看到过这个问题,但似乎没有人发布答案.有人可以帮忙吗?

解决方法:

我设法使用ndk-build方法构建它,使用此处的信息:How to build protocol buffer by Android NDK

要设置配置脚本,我运行了以下命令:

export CFLAGS="-march=armv7-a -mfloat-abi=softfp -DGoogle_PROTOBUF_NO_RTTI"export CC=arm-linux-androIDeabi-gccexport SYSROOT=$NDK/platforms/androID-9/arch-arm./configure --host=arm-eabi --with-sysroot=$SYSROOT CC=$CC --enable-cross-compile --with-protoc=protoc liBS="-lc"

这是我使用的Application.mk:

APP_STL := gnustl_staticAPP_ABI := armeabi-v7a armeabiAPP_PROJECT_PATH := ./APP_BUILD_SCRIPT := ./AndroID.mk

并使用AndroID.mk:

# copyright (C) 2009 The AndroID Open Source Project## licensed under the Apache license, Version 2.0 (the "license");# you may not use this file except in compliance with the license.# You may obtain a copy of the license at##      http://www.apache.org/licenses/liCENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the license is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd.# See the license for the specific language governing permissions and# limitations under the license.##LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)CC_liTE_SRC_fileS := \src/Google/protobuf/stubs/common.cc                              \src/Google/protobuf/stubs/once.cc                                \src/Google/protobuf/extension_set.cc                             \src/Google/protobuf/generated_message_util.cc                    \src/Google/protobuf/message_lite.cc                              \src/Google/protobuf/repeated_fIEld.cc                            \src/Google/protobuf/wire_format_lite.cc                          \src/Google/protobuf/io/coded_stream.cc                           \src/Google/protobuf/io/zero_copy_stream.cc                       \src/Google/protobuf/io/zero_copy_stream_impl_lite.ccCOMPILER_SRC_fileS :=  \src/Google/protobuf/descriptor.cc \src/Google/protobuf/descriptor.pb.cc \src/Google/protobuf/descriptor_database.cc \src/Google/protobuf/dynamic_message.cc \src/Google/protobuf/extension_set.cc \src/Google/protobuf/extension_set_heavy.cc \src/Google/protobuf/generated_message_reflection.cc \src/Google/protobuf/generated_message_util.cc \src/Google/protobuf/message.cc \src/Google/protobuf/message_lite.cc \src/Google/protobuf/reflection_ops.cc \src/Google/protobuf/repeated_fIEld.cc \src/Google/protobuf/service.cc \src/Google/protobuf/text_format.cc \src/Google/protobuf/unkNown_fIEld_set.cc \src/Google/protobuf/wire_format.cc \src/Google/protobuf/wire_format_lite.cc \src/Google/protobuf/compiler/code_generator.cc \src/Google/protobuf/compiler/command_line_interface.cc \src/Google/protobuf/compiler/importer.cc \src/Google/protobuf/compiler/main.cc \src/Google/protobuf/compiler/parser.cc \src/Google/protobuf/compiler/plugin.cc \src/Google/protobuf/compiler/plugin.pb.cc \src/Google/protobuf/compiler/subprocess.cc \src/Google/protobuf/compiler/zip_writer.cc \src/Google/protobuf/compiler/cpp/cpp_enum.cc \src/Google/protobuf/compiler/cpp/cpp_enum_fIEld.cc \src/Google/protobuf/compiler/cpp/cpp_extension.cc \src/Google/protobuf/compiler/cpp/cpp_fIEld.cc \src/Google/protobuf/compiler/cpp/cpp_file.cc \src/Google/protobuf/compiler/cpp/cpp_generator.cc \src/Google/protobuf/compiler/cpp/cpp_helpers.cc \src/Google/protobuf/compiler/cpp/cpp_message.cc \src/Google/protobuf/compiler/cpp/cpp_message_fIEld.cc \src/Google/protobuf/compiler/cpp/cpp_primitive_fIEld.cc \src/Google/protobuf/compiler/cpp/cpp_service.cc \src/Google/protobuf/compiler/cpp/cpp_string_fIEld.cc \src/Google/protobuf/compiler/java/java_enum.cc \src/Google/protobuf/compiler/java/java_enum_fIEld.cc \src/Google/protobuf/compiler/java/java_extension.cc \src/Google/protobuf/compiler/java/java_fIEld.cc \src/Google/protobuf/compiler/java/java_file.cc \src/Google/protobuf/compiler/java/java_generator.cc \src/Google/protobuf/compiler/java/java_helpers.cc \src/Google/protobuf/compiler/java/java_message.cc \src/Google/protobuf/compiler/java/java_message_fIEld.cc \src/Google/protobuf/compiler/java/java_primitive_fIEld.cc \src/Google/protobuf/compiler/java/java_service.cc \src/Google/protobuf/compiler/javamicro/javamicro_enum.cc \src/Google/protobuf/compiler/javamicro/javamicro_enum_fIEld.cc \src/Google/protobuf/compiler/javamicro/javamicro_fIEld.cc \src/Google/protobuf/compiler/javamicro/javamicro_file.cc \src/Google/protobuf/compiler/javamicro/javamicro_generator.cc \src/Google/protobuf/compiler/javamicro/javamicro_helpers.cc \src/Google/protobuf/compiler/javamicro/javamicro_message.cc \src/Google/protobuf/compiler/javamicro/javamicro_message_fIEld.cc \src/Google/protobuf/compiler/javamicro/javamicro_primitive_fIEld.cc \src/Google/protobuf/compiler/python/python_generator.cc \src/Google/protobuf/io/coded_stream.cc \src/Google/protobuf/io/gzip_stream.cc \src/Google/protobuf/io/printer.cc \src/Google/protobuf/io/tokenizer.cc \src/Google/protobuf/io/zero_copy_stream.cc \src/Google/protobuf/io/zero_copy_stream_impl.cc \src/Google/protobuf/io/zero_copy_stream_impl_lite.cc \src/Google/protobuf/stubs/common.cc \src/Google/protobuf/stubs/once.cc \src/Google/protobuf/stubs/structurally_valID.cc \src/Google/protobuf/stubs/strutil.cc \src/Google/protobuf/stubs/substitute.cc# C++ full library# =======================================================#include $(CLEAR_VARS)LOCAL_MODulE := libprotobuf-liteLOCAL_MODulE_Tags := optionalLOCAL_CPP_EXTENSION := .ccLOCAL_SRC_fileS := $(CC_liTE_SRC_fileS)                                             #\#src/Google/protobuf/stubs/strutil.cc                             \#src/Google/protobuf/stubs/substitute.cc                          \#src/Google/protobuf/stubs/structurally_valID.cc                  \#src/Google/protobuf/descriptor.cc                                \#src/Google/protobuf/descriptor.pb.cc                             \#src/Google/protobuf/descriptor_database.cc                       \#src/Google/protobuf/dynamic_message.cc                           \#src/Google/protobuf/extension_set_heavy.cc                       \#src/Google/protobuf/generated_message_reflection.cc              \#src/Google/protobuf/message.cc                                   \#src/Google/protobuf/reflection_ops.cc                            \#src/Google/protobuf/service.cc                                   \#src/Google/protobuf/text_format.cc                               \#src/Google/protobuf/unkNown_fIEld_set.cc                         \#src/Google/protobuf/wire_format.cc                               \#src/Google/protobuf/io/gzip_stream.cc                            \#src/Google/protobuf/io/printer.cc                                \#src/Google/protobuf/io/tokenizer.cc                              \#src/Google/protobuf/io/zero_copy_stream_impl.cc                  \#src/Google/protobuf/compiler/importer.cc                         \#src/Google/protobuf/compiler/parser.ccLOCAL_C_INCLUDES := $(LOCAL_PATH)/srcLOCAL_C_INCLUDES := $(LOCAL_PATH)/androID \bionic $(LOCAL_PATH)/src $(JNI_H_INCLUDE)LOCAL_SHARED_liBRARIES := \libz libcutils libutilsLOCAL_LDliBS := -lz# stlport conflicts with the host stl library#ifneq ($(TARGET_SIMulATOR),true)#LOCAL_C_INCLUDES += external/stlport/stlport#LOCAL_SHARED_liBRARIES += libstlport#endif# define the header files to be copIEd#LOCAL_copY_headerS := \#    src/Google/protobuf/stubs/once.h \#    src/Google/protobuf/stubs/common.h \#    src/Google/protobuf/io/coded_stream.h \#    src/Google/protobuf/generated_message_util.h \#    src/Google/protobuf/repeated_fIEld.h \#    src/Google/protobuf/extension_set.h \#    src/Google/protobuf/wire_format_lite_inl.h##LOCAL_copY_headerS_TO := $(LOCAL_MODulE)LOCAL_CFLAGS := -DGoogle_PROTOBUF_NO_RTTIinclude $(BUILD_SHARED_liBRARY)

要在我正在使用Protocol Buffers的其他NDK项目中包含构建的库,我必须使用库将库复制到项目的jni文件夹中并修改其AndroID.mk以添加对它的引用:

......LOCAL_LDliBS := -llog -lOpenSLES -lGLESv2 jni/libprotobuf-lite.so   include $(BUILD_SHARED_liBRARY)include $(CLEAR_VARS)LOCAL_MODulE := protobuf-liteLOCAL_SRC_fileS := libprotobuf-lite.so include $(PREBUILT_SHARED_liBRARY)

我认为就是这样,希望有人发现它有用.

总结

以上是内存溢出为你收集整理的android – 使用独立NDK工具链构建协议缓冲区全部内容,希望文章能够帮你解决android – 使用独立NDK工具链构建协议缓冲区所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1109816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存