程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 寫binder客戶端與服務端碰到的編譯錯誤

寫binder客戶端與服務端碰到的編譯錯誤

編輯:關於C語言

調試C++使用binder進行兩個進程通訊的代碼編譯錯誤,記錄下來給朋友們作為參考:

 


1、BpBInder端客戶端函數未定義,如
target SharedLib: libgui (out/target/product/generic/obj/SHARED_LIBRARIES/libgui_intermediates/LINKED/libgui.so)
out/target/product/generic/obj/SHARED_LIBRARIES/libgui_intermediates/IPlayerServer.o:(.data.rel.ro._ZTVN7android11BnInterfaceINS_13IPlayerServerEEE[vtable for android::BnInterface<android::IPlayerServer>]+0x20): undefined reference to `android::IPlayerServer::handleToPlayerid(int, int)'


class IPlayerServer : public IInterface
{
public:
    DECLARE_META_INTERFACE(PlayerServer);


    virtual Vector<Player> getPlayerList() = 0;
    virtual int handleToPlayerid(int type, int handle) ;
};


這是由於虛函數定義沒有默認實現的問題
改成如此即可
virtual int handleToPlayerid(int type, int handle) =0;


2、BpBinder端沒有對Flattenable interface進行定義實現
target thumb C++: libgui <= frameworks/base/libs/gui/Player.cpp
frameworks/base/libs/gui/Player.cpp:63: error: no 'size_t android::Player::getFlattenedSize() const' member function declared in class 'android::Player'
frameworks/base/libs/gui/Player.cpp:72: error: no 'size_t android::Player::getFdCount() const' member function declared in class 'android::Player'


增加:
    // Flattenable interface
    virtual size_t getFlattenedSize() const;
    virtual size_t getFdCount() const;
    virtual status_t flatten(void* buffer, size_t size,
            int fds[], size_t count) const;
    virtual status_t unflatten(void const* buffer, size_t size,
            int fds[], size_t count);
並實現即可


3、未繼承class RefBase 類導致問題
frameworks/base/include/utils/RefBase.h:331: error: 'class android::PlayerDevice' has no member named 'decStrong'
frameworks/base/include/utils/RefBase.h: In member function 'android::sp<T>& android::sp<T>::operator=(T*) [with T = android::PlayerDevice]':
frameworks/base/services/multiplayerservice/MultiplayerService.cpp:55:   instantiated from here
frameworks/base/include/utils/RefBase.h:346: error: 'class android::PlayerDevice' has no member named 'incStrong'
frameworks/base/include/utils/RefBase.h:347: error: 'class android::PlayerDevice' has no member named 'decStrong'


增加一下RefBase類即可
class PlayerDevice:
public Singleton<PlayerDevice>,
public RefBase
{


4、匯編代碼問題(linear_src.c 中使用assemble.h)
/tmp/ccVb1LeR.s: Assembler messages:
/tmp/ccVb1LeR.s:476: Error: selected processor does not support `smull r6,r1,r3,r1'


網上找的答案是:
ALWAYS_BUILD_AS_ARM
放置在mmp第一行,可以避免各類SDK版本下編譯內嵌arm匯編碼出現thumb指令集導致的編譯錯誤
症狀類似:
gcce編譯器的
Error: selected processor does not support `smull r0,r3,r6,r3′
armcc編譯器的
Inline assembler not permitted when generating Thumb code
__asm {
...
}

由於assembly.h是以inline定義,代碼宏替換後報錯,所以在gcc make編譯選項中想辦法:
在編譯此文件中加入
LOCAL_CFLAGS += -mno-thumb-interwork -mno-thumb -marm


5、 android2.3版本的 android_native_window_t 結構變更
typedef struct ANativeWindow android_native_window_t;
所以struct android_native_window_t --> android_native_window_t 變更即可
而2.2沒有定義ANativeWindow結構

6、加入如下語句
ifdef FIXED_ARCH_TYPE
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/preprocessor/$(FIXED_ARCH_TYPE)/libglslPreprocessor.a)
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/compiler/$(FIXED_ARCH_TYPE)/libglslCompiler.a)
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/entry/$(FIXED_ARCH_TYPE)/libGLESv2SC.a)
endif

編譯報找不到LOCAL_MODULE_TAGS定義,解決方法:
add-prebuilt-files的定義是在build/core/definitions.mk下,在include-prebuilt定義加入


define include-prebuilt
    include $$(CLEAR_VARS)
...
    LOCAL_MODULE_TAGS := eng  (增加此句即可)
    include $$(BUILD_PREBUILT)

endef

 

andyhuabing的專欄
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved