Android framework中使用stl库

来源:互联网 发布:大学毕业后悔做程序员 编辑:程序博客网 时间:2024/06/04 19:33

在Android的framework或者ndk中使用stl库中的方法,如std::string 时需要修改Android.mk文件添加相应的库支持。

主要步骤如下:

   LOCAL_SHARED_LIBRARIES中添加libstlport;

   LOCAL_C_INCLUDES中添加    external/stlport/stlport  bionic  bionic/libc/private


如下为本文修改的方法:

# Copyright (C) 2010 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)LOCAL_SRC_FILES := test.cppLOCAL_SHARED_LIBRARIES := \    libandroid_runtime \    libcutils \    libutils \    liblog  \    libnativehelper \    libstlport  \    LOCAL_C_INCLUDES += \    $(JNI_H_INCLUDE) \    external/stlport/stlport \    bionic \    bionic/libc/private \          LOCAL_MODULE:= liblsphoneinclude $(BUILD_SHARED_LIBRARY)

使用demo

在cpp中使用std标准库中的string类时需要注意如下步骤:

1.导入头文件

   #include <string>

2.添加类的引用命名空间

   using namespace std;

0 0
原创粉丝点击