windows下使用ndk編譯grpc
下載grpc
https://github.com/grpc/grpc.git
git checkout release-0_9_1
使用nodejs由build.json生成Android.mk
新建gen-ndk.js,內容如下
var fs = require("fs");
var build = JSON.parse(fs.readFileSync("build.json", "utf8"));
var libs = build.libs;
process.stdout.write('LOCAL_PATH := $(call my-dir) \n');
process.stdout.write ('SRC_PATH := ..\n')
function getGroup(name)
{
for (var i = 0; i < build.filegroups.length; i++)
if (build.filegroups[i].name == name)
return build.filegroups[i];
}
for (var i = 0; i < libs.length; i++) {
if (libs[i].build == 'all' && libs[i].secure == 'no' ) {
process.stdout.write('\n\ninclude $(CLEAR_VARS)\n')
process.stdout.write('LOCAL_MODULE_TAGS:= optional\n');
process.stdout.write('LOCAL_MODULE:= ' + libs[i].name + '\n')
var headers = {};
headers['include'] = 'include';
if (libs[i].headers != undefined) {
for (var j = 0; j < libs[i].headers.length; j++) {
var path = libs[i].headers[j];
var last = path.lastIndexOf('/');
path = path.substr(0, last);
headers[path] = path;
}
}
if (libs[i].deps !== undefined) {
process.stdout.write('LOCAL_SHARED_LIBRARIES:=')
for (var j = 0; j < libs[i].deps.length; j++) {
process.stdout.write(libs[i].deps[j] + ' ');
}
process.stdout.write('\n');
}
process.stdout.write('LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz\n');
process.stdout.write('LOCAL_SRC_FILES:= \\\n');
if (libs[i].src !== undefined) {
for (var j = 0; j < libs[i].src.length; j++) {
process.stdout.write('\t$(SRC_PATH)/' + libs[i].src[j] + ' \\\n');
}
}
if (libs[i].filegroups !== undefined) {
for (var j = 0; j < libs[i].filegroups.length; j++) {
var group = getGroup(libs[i].filegroups[j]);
for (var k = 0; k < group.src.length; k++)
process.stdout.write('\t$(SRC_PATH)/' + group.src[k] + ' \\\n');
if (group.headers != undefined) {
for (var k = 0; k < group.headers.length; k++) {
var path = group.headers[k];
var last = path.lastIndexOf('/');
path = path.substr(0, last);
headers[path] = path;
}
}
}
}
process.stdout.write('\nLOCAL_C_INCLUDES:= \\\n')
process.stdout.write('\t$(LOCAL_PATH)/../include \\\n');
process.stdout.write('\t$(LOCAL_PATH)/../ \\\n');
process.stdout.write('\t$(LOCAL_PATH)/../../protobuf/src \\\n');
process.stdout.write('\ninclude $(BUILD_SHARED_LIBRARY)\n');
}
}
生成的Android.mk內容如下
LOCAL_PATH := $(call my-dir)
SRC_PATH := ..
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE:= gpr
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
LOCAL_SRC_FILES:= \
$(SRC_PATH)/src/core/support/alloc.c \
$(SRC_PATH)/src/core/support/cancellable.c \
$(SRC_PATH)/src/core/support/cmdline.c \
$(SRC_PATH)/src/core/support/cpu_iphone.c \
$(SRC_PATH)/src/core/support/cpu_linux.c \
$(SRC_PATH)/src/core/support/cpu_posix.c \
$(SRC_PATH)/src/core/support/cpu_windows.c \
$(SRC_PATH)/src/core/support/env_linux.c \
$(SRC_PATH)/src/core/support/env_posix.c \
$(SRC_PATH)/src/core/support/env_win32.c \
$(SRC_PATH)/src/core/support/file.c \
$(SRC_PATH)/src/core/support/file_posix.c \
$(SRC_PATH)/src/core/support/file_win32.c \
$(SRC_PATH)/src/core/support/histogram.c \
$(SRC_PATH)/src/core/support/host_port.c \
$(SRC_PATH)/src/core/support/log.c \
$(SRC_PATH)/src/core/support/log_android.c \
$(SRC_PATH)/src/core/support/log_linux.c \
$(SRC_PATH)/src/core/support/log_posix.c \
$(SRC_PATH)/src/core/support/log_win32.c \
$(SRC_PATH)/src/core/support/murmur_hash.c \
$(SRC_PATH)/src/core/support/slice.c \
$(SRC_PATH)/src/core/support/slice_buffer.c \
$(SRC_PATH)/src/core/support/string.c \
$(SRC_PATH)/src/core/support/string_posix.c \
$(SRC_PATH)/src/core/support/string_win32.c \
$(SRC_PATH)/src/core/support/subprocess_posix.c \
$(SRC_PATH)/src/core/support/sync.c \
$(SRC_PATH)/src/core/support/sync_posix.c \
$(SRC_PATH)/src/core/support/sync_win32.c \
$(SRC_PATH)/src/core/support/thd.c \
$(SRC_PATH)/src/core/support/thd_posix.c \
$(SRC_PATH)/src/core/support/thd_win32.c \
$(SRC_PATH)/src/core/support/time.c \
$(SRC_PATH)/src/core/support/time_posix.c \
$(SRC_PATH)/src/core/support/time_win32.c \
$(SRC_PATH)/src/core/support/tls_pthread.c \
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../ \
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE:= grpc_unsecure
LOCAL_SHARED_LIBRARIES:=gpr
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
LOCAL_SRC_FILES:= \
$(SRC_PATH)/src/core/surface/init_unsecure.c \
$(SRC_PATH)/src/core/channel/census_filter.c \
$(SRC_PATH)/src/core/channel/channel_args.c \
$(SRC_PATH)/src/core/channel/channel_stack.c \
$(SRC_PATH)/src/core/channel/child_channel.c \
$(SRC_PATH)/src/core/channel/client_channel.c \
$(SRC_PATH)/src/core/channel/client_setup.c \
$(SRC_PATH)/src/core/channel/connected_channel.c \
$(SRC_PATH)/src/core/channel/http_client_filter.c \
$(SRC_PATH)/src/core/channel/http_server_filter.c \
$(SRC_PATH)/src/core/channel/noop_filter.c \
$(SRC_PATH)/src/core/compression/algorithm.c \
$(SRC_PATH)/src/core/compression/message_compress.c \
$(SRC_PATH)/src/core/debug/trace.c \
$(SRC_PATH)/src/core/iomgr/alarm.c \
$(SRC_PATH)/src/core/iomgr/alarm_heap.c \
$(SRC_PATH)/src/core/iomgr/endpoint.c \
$(SRC_PATH)/src/core/iomgr/endpoint_pair_posix.c \
$(SRC_PATH)/src/core/iomgr/endpoint_pair_windows.c \
$(SRC_PATH)/src/core/iomgr/fd_posix.c \
$(SRC_PATH)/src/core/iomgr/iocp_windows.c \
$(SRC_PATH)/src/core/iomgr/iomgr.c \
$(SRC_PATH)/src/core/iomgr/iomgr_posix.c \
$(SRC_PATH)/src/core/iomgr/iomgr_windows.c \
$(SRC_PATH)/src/core/iomgr/pollset_kick.c \
$(SRC_PATH)/src/core/iomgr/pollset_multipoller_with_epoll.c \
$(SRC_PATH)/src/core/iomgr/pollset_multipoller_with_poll_posix.c \
$(SRC_PATH)/src/core/iomgr/pollset_posix.c \
$(SRC_PATH)/src/core/iomgr/pollset_windows.c \
$(SRC_PATH)/src/core/iomgr/resolve_address_posix.c \
$(SRC_PATH)/src/core/iomgr/resolve_address_windows.c \
$(SRC_PATH)/src/core/iomgr/sockaddr_utils.c \
$(SRC_PATH)/src/core/iomgr/socket_utils_common_posix.c \
$(SRC_PATH)/src/core/iomgr/socket_utils_linux.c \
$(SRC_PATH)/src/core/iomgr/socket_utils_posix.c \
$(SRC_PATH)/src/core/iomgr/socket_windows.c \
$(SRC_PATH)/src/core/iomgr/tcp_client_posix.c \
$(SRC_PATH)/src/core/iomgr/tcp_client_windows.c \
$(SRC_PATH)/src/core/iomgr/tcp_posix.c \
$(SRC_PATH)/src/core/iomgr/tcp_server_posix.c \
$(SRC_PATH)/src/core/iomgr/tcp_server_windows.c \
$(SRC_PATH)/src/core/iomgr/tcp_windows.c \
$(SRC_PATH)/src/core/iomgr/time_averaged_stats.c \
$(SRC_PATH)/src/core/iomgr/wakeup_fd_eventfd.c \
$(SRC_PATH)/src/core/iomgr/wakeup_fd_nospecial.c \
$(SRC_PATH)/src/core/iomgr/wakeup_fd_pipe.c \
$(SRC_PATH)/src/core/iomgr/wakeup_fd_posix.c \
$(SRC_PATH)/src/core/json/json.c \
$(SRC_PATH)/src/core/json/json_reader.c \
$(SRC_PATH)/src/core/json/json_string.c \
$(SRC_PATH)/src/core/json/json_writer.c \
$(SRC_PATH)/src/core/profiling/basic_timers.c \
$(SRC_PATH)/src/core/profiling/stap_timers.c \
$(SRC_PATH)/src/core/statistics/census_init.c \
$(SRC_PATH)/src/core/statistics/census_log.c \
$(SRC_PATH)/src/core/statistics/census_rpc_stats.c \
$(SRC_PATH)/src/core/statistics/census_tracing.c \
$(SRC_PATH)/src/core/statistics/hash_table.c \
$(SRC_PATH)/src/core/statistics/window_stats.c \
$(SRC_PATH)/src/core/surface/byte_buffer.c \
$(SRC_PATH)/src/core/surface/byte_buffer_queue.c \
$(SRC_PATH)/src/core/surface/byte_buffer_reader.c \
$(SRC_PATH)/src/core/surface/call.c \
$(SRC_PATH)/src/core/surface/call_details.c \
$(SRC_PATH)/src/core/surface/call_log_batch.c \
$(SRC_PATH)/src/core/surface/channel.c \
$(SRC_PATH)/src/core/surface/channel_create.c \
$(SRC_PATH)/src/core/surface/client.c \
$(SRC_PATH)/src/core/surface/completion_queue.c \
$(SRC_PATH)/src/core/surface/event_string.c \
$(SRC_PATH)/src/core/surface/init.c \
$(SRC_PATH)/src/core/surface/lame_client.c \
$(SRC_PATH)/src/core/surface/metadata_array.c \
$(SRC_PATH)/src/core/surface/server.c \
$(SRC_PATH)/src/core/surface/server_chttp2.c \
$(SRC_PATH)/src/core/surface/server_create.c \
$(SRC_PATH)/src/core/surface/surface_trace.c \
$(SRC_PATH)/src/core/transport/chttp2/alpn.c \
$(SRC_PATH)/src/core/transport/chttp2/bin_encoder.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_data.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_goaway.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_ping.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_rst_stream.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_settings.c \
$(SRC_PATH)/src/core/transport/chttp2/frame_window_update.c \
$(SRC_PATH)/src/core/transport/chttp2/hpack_parser.c \
$(SRC_PATH)/src/core/transport/chttp2/hpack_table.c \
$(SRC_PATH)/src/core/transport/chttp2/huffsyms.c \
$(SRC_PATH)/src/core/transport/chttp2/status_conversion.c \
$(SRC_PATH)/src/core/transport/chttp2/stream_encoder.c \
$(SRC_PATH)/src/core/transport/chttp2/stream_map.c \
$(SRC_PATH)/src/core/transport/chttp2/timeout_encoding.c \
$(SRC_PATH)/src/core/transport/chttp2/varint.c \
$(SRC_PATH)/src/core/transport/chttp2_transport.c \
$(SRC_PATH)/src/core/transport/metadata.c \
$(SRC_PATH)/src/core/transport/stream_op.c \
$(SRC_PATH)/src/core/transport/transport.c \
$(SRC_PATH)/src/core/transport/transport_op_string.c \
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../ \
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := $(SRC_PATH)/libprotobuf.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE:= grpc++_unsecure
LOCAL_SHARED_LIBRARIES:=gpr grpc_unsecure libprotobuf
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
LOCAL_SRC_FILES:= \
$(SRC_PATH)/src/cpp/client/channel.cc \
$(SRC_PATH)/src/cpp/client/channel_arguments.cc \
$(SRC_PATH)/src/cpp/client/client_context.cc \
$(SRC_PATH)/src/cpp/client/client_unary_call.cc \
$(SRC_PATH)/src/cpp/client/create_channel.cc \
$(SRC_PATH)/src/cpp/client/credentials.cc \
$(SRC_PATH)/src/cpp/client/generic_stub.cc \
$(SRC_PATH)/src/cpp/client/insecure_credentials.cc \
$(SRC_PATH)/src/cpp/client/internal_stub.cc \
$(SRC_PATH)/src/cpp/common/call.cc \
$(SRC_PATH)/src/cpp/common/completion_queue.cc \
$(SRC_PATH)/src/cpp/common/rpc_method.cc \
$(SRC_PATH)/src/cpp/proto/proto_utils.cc \
$(SRC_PATH)/src/cpp/server/async_generic_service.cc \
$(SRC_PATH)/src/cpp/server/insecure_server_credentials.cc \
$(SRC_PATH)/src/cpp/server/server.cc \
$(SRC_PATH)/src/cpp/server/server_builder.cc \
$(SRC_PATH)/src/cpp/server/server_context.cc \
$(SRC_PATH)/src/cpp/server/server_credentials.cc \
$(SRC_PATH)/src/cpp/server/thread_pool.cc \
$(SRC_PATH)/src/cpp/util/byte_buffer.cc \
$(SRC_PATH)/src/cpp/util/slice.cc \
$(SRC_PATH)/src/cpp/util/status.cc \
$(SRC_PATH)/src/cpp/util/time.cc \
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../../protobuf/src
include $(BUILD_SHARED_LIBRARY)
建立Application.mk,內容如下
APP_MODULES := gpr grpc_unsecure grpc++_unsecure
APP_PLATFORM := android-9
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_OPTIM := release
NDK_TOOLCHAIN_VERSION := clang
APP_CPPFLAGS := -fexceptions -frtti -std=c++11
編譯後得到gpr grpc_unsecure grpc++_unsecure,就是我們所需要的。
遇到的問題:
預設使用grpc庫連結得到的程式,執行的時候會提示下面錯誤,
CANNOT LINK EXECUTABLE: could not load library "libgrpc_unsecure.so" needed by "xxx"; caused by cannot locate symbol "__tls_get_addr" referenced by "libgrpc_unsecure.so"...
做下面的修改就可以了,使用android libthread自己的tls
diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h
index a695acf..f36ac63 100644
--- a/include/grpc/support/port_platform.h
+++ b/include/grpc/support/port_platform.h
@@ -67,7 +67,8 @@
#define GPR_ARCH_32 1
#define GPR_CPU_LINUX 1
#define GPR_GCC_SYNC 1
-#define GPR_GCC_TLS 1
+//#define GPR_GCC_TLS 1
+#define GPR_PTHREAD_TLS 1
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1
#define GPR_POSIX_WAKEUP_FD 1
#define GPR_LINUX_EVENTFD 1
相關推薦
windows下使用ndk編譯grpc
下載grpc https://github.com/grpc/grpc.git git checkout release-0_9_1 使用nodejs由build.json生成Android.mk 新建gen-ndk.js,內容如下 var
Windows下VS2017編譯OpenCV 3.4.0-rc
打開 extra 地址 erl lap 頭文件 mas encode master 簡述 很久沒有用過OpenCV了,這次需要做一點圖像處理相關的工作,又需要用起來,這裏記錄一下編譯的過程。之前介紹過使用vs2015編譯opencv2.4的帖子在這裏。 編譯好的文件在這裏h
JAVA 基礎開發環境 vscode 搭建 Windows下VSCode編譯運行簡單java
ast devel article not warning 環境 type cal gate JAVA 基礎開發環境 vscode 搭建 來源 https://www.cnblogs.com/freewsf/p/7744728.html 對於使用 Visual Stu
windows下vc編譯和debug nginx
topic 命令行 zlib err pack its fd_set figure htm 總體來說,各個步驟以及版本參考官方文檔http://nginx.org/en/docs/howto_build_on_win32.html一點沒錯,有些細節沒說清楚。 To buil
windows下vs2015編譯BOOST
命令 graph all project model dep 找到 動態鏈接庫 con 編譯caffe動態鏈接庫,在vs下引用時缺少boost的相關運行庫,dependency下也沒有找到,於是自己本機編譯boost庫: step1 打開vs命令行工具 在啟動菜單下找到vs
Windows下PythonQt編譯(vs2015+Qt5.11.2+PythonQt 3.2)
測試的 pat qt 5 圖片 引入 以及 .org add info 時間:2018年10月22日,學習任何物事都有個探索過程。歡迎留言探討。 在Qt程序中,添加python進行混合編程,可以使用Python API,但交互起來很麻煩,不友好。網上推薦使用Python
Windows下vs2013編譯ffmpeg原始碼
在蒐羅網上各種資源以及網上請教各位大聲終於在今天晚上編譯成功,經測試編譯出來的庫可正常使用,故可證明編譯正確。在此特感謝群裡大神的幫助。感謝雷神 現將具體步驟記錄如下; 本人編譯用的是vs2013,在win7系統下,對ffmpeg-3.0進行編譯,其他版本尚未測試,後續若有問題會補充。
windows下ant編譯生成hadoop-eclipse-plugin外掛解決辦法
我目前用的hadoop2.9.0版本,之前應該是用hadoop2.6以下的版本的時候,直接從網上下載hadoop-eclipse-plugin-**.jar拷貝到eclipse/plugins下就解決了,後面的版本看網上介紹需要用ant編譯生成
libvpx在Windows下的編譯
因為要實現一個基於libvpx的視訊編解碼庫,而軟體執行環境又是Windows下,因此寫這個部落格記錄自己的編譯過程,不少東西都是借用的前輩們的經驗,自己則是簡單地記錄一下。 首先安裝Wi
VSCode Windows下VSCode編譯除錯c/c++更新launch和tasks 2018.03.27
新的launch.json // Available variables which can be used inside of strings. // ${workspaceRoot}: the root folder of the team // ${f
windows下cmake編譯opencv3.4.1+opencv_contrib報錯
問題一: CMake Warning (dev) at cmake/common.cmake:5 (source_group): Syntax error in cmake code at C:/yumen/wxgisgdal-read-only/c
Windows下如何編譯使用boost?
最近在看boost::asio的東西,所以必須要用到boost庫,下載了一個,所以與大家分享下boost庫的編譯方法。本方法應該適用於boost的任何版本,應該適用於任何C++編譯器(VC6.0可能對某些庫不支援,因為模板的原因),因為Linux沒怎麼用,所以只是分享下windows上的編譯方法。1.下載bo
SQLCipher Windows下的編譯
由於專案需要,需要編譯SQLCipher 以便保持ios android windows統一 1.安裝vs2013,其他的我沒有測試過 2.安裝 Activestate Perl, 下載地址http://www.activestate.com/activeperl 3.下載並編譯
【VSCode】Windows下VSCode編譯除錯c/c++【更新】
————————– 2017.06.10 更新————————- 便攜版已更新,點此獲取便攜版 用於cpptools外掛的配置檔案更新 更新的launch.json // Available variables which can be used inside of strings. // ${work
【VSCode】Windows下VSCode編譯執行簡單java
注意:這篇文章內容已經過時,請勿按此文章所介紹方法實踐,浪費時間後果自負。 先看效果: 配置流程: JDK & JRE 的配置(不細講了網上一大堆) VSCode的下載安裝以及外掛c
boost 在windows下的編譯及使用
備註: 你可以編譯全部boost庫或是隻是編譯你想要的庫,也就是說你可以根據需要選擇要編譯哪些庫,這點非常重要,因為boost是如此龐大,完全編譯很是耗時間的,初步估計要1小時,況且也耗資源,編譯出來需要1G多空間呢,暈。因此一般使用的時候都不會編譯整個boost
Windows下 caffe編譯好檔案,帶例子
執行Lenet 首先,配置環境變數,.\caffe-master\Build\x64\Release 例子在解壓包裡的 caffe-master/examples/mnist//train_lenet .bat 對應的mnist資料已轉換好,配置好環境即可執行
【VSCode】Windows下VSCode編譯除錯c/c++
本文轉自:http://blog.csdn.net/c_duoduo/article/details/51615381 本人根據自己的操作,修改了一些細節,用於C語言除錯。 ————————– 以下是原文 ————————- 這篇文章為blackkitty記錄在w
Windows下CUnit編譯安裝教程
工作需要在Win端編譯一個開源庫,而這個開源庫依賴於CUnit。在sourceforge下載了CUnit-2.1-3,而文件的編譯方法在win下根本編譯不過去。去百度編譯方法,卻發現結果都是錯的,最後
Golang windows下交叉編譯的方法
Golang windows下交叉編譯的方法 在CMD命令列中編譯(示例編譯64位linux程式) set GOARCH=amd64 set GOOS=linux go build xxx.go 在windows10之前的系統版本上使用cmd命令列可以使用上述