android 編譯STL模組相關錯誤解決

2021-06-18 05:05:29 字數 3038 閱讀 6513

由於android系統目前沒有將boost加入,這裡面使用了大量的stl及c++的一些語言特性,導致編譯出現令人非常頭痛的問題。

1、出現類似的異常函式錯誤

boost/exception/detail/exception_ptr.hpp:382: error: expected ';' before 'catch'

boost/exception/detail/exception_ptr.hpp:387: error: expected primary-expression before 'catch

boost/throw_exception.hpp:48: error: in passing argument 1 of 'void boost::throw_exception(const std::exception&)'

解決方案:

此問題的出現是編譯器的異常異常捕獲被禁用了,需要在android.mk檔案中開啟。

在android.mk檔案中新增:local_cppflags += -fexceptions就可以了。

並且android平台提供了乙個最小化的c++執行庫(/system/lib/libstdc++)以及與之對應的標頭檔案。

原因:只有異常安全的**才應該用-fexceptions編譯吧(這在編譯c++的時候是預設選項)。

絕大部分c**都不是異常安全的,如果沒加-fexceptions,異常經過的時候程式會直接退出,加了-fexceptions以後,萬一它呼叫的某個函式丟擲了異常,

也會直接經過這段**,弄不好會出現記憶體洩漏之類的問題而不報錯吧。

所以對於try{}catch{}的關鍵字使用時需要加上 -fexceptions

-frtti:

開啟rtti(runtime type identification)?這樣編譯器會為每個有虛函式的類新增一些資訊以支援rtti特性,例如dynamic_cast typeid之類.   

可以使用-fno-rtti來關閉這個特性節約空間

2、stl模組函式找不到,鏈結失敗

stdc++/include/bits/stl_list.h:466: error: undefined reference to '__cxa_end_catch

stdc++/include/bits/stl_list.h:469: error: undefined reference to '__cxa_rethrow'

nal_based1ev+0x0): error: undefined reference to '__gxx_personality_v0'

這些函式在 libsupc++.a庫中,加上即可

ist.h:1424: error: undefined reference to 'std::_list_node_base::unhook()'

stdc++/include/bits/list.tcc:101: error: undefined reference to 'std::_list_node_base::hook(std::_list_node_base*)

這些函式在 libstdc++.a庫中,加上即可

在android4.2系統中如此使用:

prebuilt_stdcxx_path := prebuilts/ndk/current/sources/cxx-stl/gnu-libstdc++

local_c_includes := \

$(prebuilt_stdcxx_path)/include \

$(prebuilt_stdcxx_path)/libs/$(target_cpu_abi)/include/ \

local_cppflags += -fexceptions -frtti

local_ldflags += -l$(prebuilt_stdcxx_path)/libs/$(target_cpu_abi) -lgnustl_static -lsupc++

對於標頭檔案的引用及庫加上,基本上可以完全解決stl庫的函式

對於stl庫,其標頭檔案及庫在android4.1版本及以上才將所有函式實現完全,所有如果還碰鏈結某個函式失敗的話,那麼可以

3、預編譯靜態庫:

build/core/base_rules.mk:81: * each module must use a local_module_tags in its

build/core/base_rules.mk:82: *

android.mk. possible tags declared by a module:

build/core/base_rules.mk:83: * 

build/core/base_rules.mk:84: *     optional, debug, eng, tests, samples

修改build\core下的檔案definitions.mk

define include-prebuilt

include $$(clear_vars)

local_src_files := $(1)

local_built_module_stem := $(1)

local_module_suffix := $$(suffix $(1))

local_module := $$(basename $(1))

local_module_class := $(2)

local_module_tags := optional  // 加上這句話即可

include $$(build_prebuilt)

endef

預編譯靜態庫指令:

local_path:= $(call my-dir)

include $(clear_vars)    www.2cto.com

$(call add-prebuilt-files, static_libraries, libboost_filesystem.a)

$(call add-prebuilt-files, static_libraries, libboost_system.a)

$(call add-prebuilt-files, static_libraries, libboost_thread.a)

2011 06 08 Android編譯模組

如果你只修改某乙個模組的內容,卻每次都要執行make,最後等待很長時間。使用模組編譯,只需要在你所在的模組的目錄或者其子目錄,執行mm,便可以編譯出乙個單獨的apk,這樣豈不快哉!具體步驟 1 開啟 baserc檔案,加入source i850 build envsetup.sh.加入你自己該檔案所...

android中的模組編譯

原則 只要有android.mk的資料夾就可以用mmm或者mm來編譯 具體的編譯用framework.jar來說明 1.首先需要設定編譯環境 export arch arm export cross compile prebuilt linux x86 toolchain arm eabi 4.4....

Android 模組新增與編譯

新增google服務 我們自己的rom裡沒有google服務 完整的google包裡包含google框架和各種服務,我們可以選擇性安裝模組 在google包裡products目錄下,有乙個 gms.mk 檔案 或者自己起名字 gms.mk管理著要安裝的各個模組,找到關鍵字product packag...