链接第三方库(动态或者静态库)到自己的生成库中

如何将第三方动态链接库连接到自己生成的动态库中,按照以下步骤:

1.首先看目录结构:首先将第三方库复制到JNILIBS下,并创建对应的CUP平台目录
2. CMAKELISTS.TXT

方式一:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

message(STATUS "******************************************************************")
message(STATUS "CMAKE_SOURCE_DIR->" ${CMAKE_SOURCE_DIR})
message(STATUS "PROJECT_SOURCE_DIR->)" ${PROJECT_SOURCE_DIR})
message(STATUS "******************************************************************")

#1.搜索源文件并赋值给变量名
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app CLIENT_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/user/source USER_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/user USER_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/device/source DEVICE_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/device DEVICE_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/event/source EVENT_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/event EVENT_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/tools TOOLS_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/helper HELPER_SRC)

#2.设置源文件到统一的变量
set(DIR_SRCS ${CLIENT_SRC} ${USER_SRC} ${USER_OP_SRC}
${DEVICE_SRC} ${DEVICE_OP_SRC} ${EVENT_SRC} ${EVENT_OP_SRC} ${TOOLS_SRC} ${HELPER_SRC})

#3.设置第三方库头文件所在位置
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/thirdInclude/)

#4.设置第三方库头库所在位置
link_directories(${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/)

#5.对应的库
link_libraries(SKYhttpClient.so SKYmxml.so)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

#6.创建动态库
add_library( # Sets the name of the library.
skyqcloud-sdk

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
${DIR_SRCS}
${CMAKE_SOURCE_DIR}/src/main/cpp/skyqc_sdk_native.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

#7.链接需要的第三方动态库
target_link_libraries( # Specifies the target library.
skyqcloud-sdk

#the third library
SKYhttpClient
SKYmxml

# Links the target library to the log library
# included in the NDK.
${log-lib} )

方式二:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

message(STATUS "******************************************************************")
message(STATUS "CMAKE_SOURCE_DIR->" ${CMAKE_SOURCE_DIR})
message(STATUS "PROJECT_SOURCE_DIR->)" ${PROJECT_SOURCE_DIR})
message(STATUS "******************************************************************")

#1.搜索源文件并赋值给变量名
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app CLIENT_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/user/source USER_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/user USER_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/device/source DEVICE_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/device DEVICE_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/event/source EVENT_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/event EVENT_OP_SRC)

aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/tools TOOLS_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/main/cpp/common/app/helper HELPER_SRC)

#2.设置源文件到统一的变量
set(DIR_SRCS ${CLIENT_SRC} ${USER_SRC} ${USER_OP_SRC}
${DEVICE_SRC} ${DEVICE_OP_SRC} ${EVENT_SRC} ${EVENT_OP_SRC} ${TOOLS_SRC} ${HELPER_SRC})

#3.设置第三方库头文件所在位置
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/thirdInclude/)

#4.导入第三方动态库
# 添加第三方动态库
add_library(SKYhttpClient
SHARED
IMPORTED)

# 设置第三方动态库属性(存储位置) armeabi-v7a
set_target_properties(SKYhttpClient
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libSKYhttpClient.so)

# 添加第三方动态库
add_library(SKYmxml
SHARED
IMPORTED)

# 设置第三方动态库属性(存储位置)
set_target_properties(SKYmxml
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libSKYmxml.so)


# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

#6.创建动态库(自己将要生成的动态库)
add_library( # Sets the name of the library.
skyqcloud-sdk

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
${DIR_SRCS}
${CMAKE_SOURCE_DIR}/src/main/cpp/skyqc_sdk_native.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

#6.链接需要的第三方动态库
target_link_libraries( # Specifies the target library.
skyqcloud-sdk

#the third library
SKYhttpClient
SKYmxml

# Links the target library to the log library
# included in the NDK.
${log-lib} )

注意:

若第三方库初始化等失败,则需要在Java文件中设置,类似:

static {
      System.loadLibrary("device");
      System.loadLibrary("ControllerAdapter");
  }

或者在初始化库函数之前,在cpp中:

#include <dlfcn.h>  
      
void *handle;  
  
handle = dlopen ("libm.so", RTLD_NOW, RTLD_LOCAL);  
if (!handle) 
{  
fprintf (stderr, "%s ", dlerror());  
    exit(1);  
}  

备注:实际开发过程中添加如下两步也可链接第三方库(动态或者静态库)到自己的生成库中,如有不对,欢迎指正。

add_library(ThreadPool SHARED main.cpp ThreadPool.cpp ThreadPool.h BlockQueue.hpp)
target_link_libraries(ThreadPool pthread)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
高效的 C++ JSON 解析/生成器,提供 SAX 及 DOM 风格 API 简介 RapidJSON 是一个 C++ 的 JSON 解析器及生成器。它的灵感来自RapidXml 。 RapidJSON 小而全。它同时支持 SAX 和 DOM 风格的 API。SAX 解析器只有约 500 行代码。 RapidJSON 快。它的性能可与 strlen() 相比。可支持 SSE2/SSE4.2 加速。 RapidJSON 独立。它不依赖于 BOOST 等外部库。它甚至不依赖于 STL。 RapidJSON 对内存友好。在大部分 32/64 位机器上,每个 JSON 值只占 16 字节(除字符串外)。它预设使用一个快速的内存分配器,令分析器可以紧凑地分配内存。 RapidJSON 对 Unicode 友好。它支持 UTF-8、UTF-16、UTF-32 (大端序/小端序),并内部支持这些编码的检测、校验及转码。例如,RapidJSON 可以在分析一个 UTF-8 文件至 DOM 时,把当中的 JSON 字符串转码至 UTF-16。它也支持代理对(surrogate pair)及 "\u0000"(空字符)。 JSON(JavaScript Object Notation)是一个轻量的xx交换格式。RapidJSON 应该完全遵从 RFC7159/ECMA-404,并支持可选的放宽语法。 一、使用说明         rapidjson.fne 为英文原版         rapidjson_cn.fne  为中文翻译版(翻译的中文命令有点糙),使用中文版时,请改文件名为rapidjson.fne 不然会出错的。         rapidjson_static.lib 为静态库,部分中文英文。         中文和英文可以无缝切换,直接替换支持库文件就可以了。         本支持库由VS2017,所以编译时,也必须要用VS2017编译。         VC2017连接器下载地址: http://bbs.eyuyan.com/read.php?tid=410252   VS2017易支持库模板+VC2017链接器(讨厌vc6的可看)-->hxznhf http://bbs.eyuyan.com/read.php?tid=408541   全易论坛独创首发,Vs2017Linker编译器 -->cs666         关于RapidJSON的相关问题,请看:http://rapidjson.org/zh-cn/md_doc_faq_8zh-cn.html         使用有声明问题请加QQ群: 心宇->EVAxx研究中心(255829517)         现在支持库完善了大概80%左右,已经可以正常使用,剩下20%是关于 reader 和编码以及一些参数有关,暂时对易不是很重要,后面也会完善。 二、版权声明         本支持库为封装TX开源项目 RapidJSON ,为解决易语言 没有高性能JSON库的问题。         项目官网:http://rapidjson.org/zh-cn/         github:https://github.com/Tencent/rapidjson/
TaskDialog信息框支持库。 操作系统支持: Windows 注意:TaskDialog信息框的API是在Vista之后才被加入的,所以,在Vista以下电脑慎用!! 前言 本程序基于CTaskDialog类,前阵子发布过一个不是很完善的程序。本次开放了:“TaskDialogCallbackProc”接口,可以对TaskDialog进行消息处理。 增加内容 增加的常量: 通知消息 wParam 值 lParam 值 TDN_CREATED 未使用。 未使用。 TDN_NAVIGATED 未使用。 未使用。 TDN_BUTTON_CLICKED 命令按钮控件ID. 未使用。 TDN_HYPERLINK_CLICKED 命令按钮控件ID. 包含指向的 LPCWSTR 结构。 TDN_TIMER 重置毫秒,因为 CTaskDialog 创建或计时器的时间。 未使用。 TDN_DESTROYED 未使用。 未使用。 TDN_RADIO_BUTTON_CLICKED 单选按钮的ID. 未使用。 TDN_DIALOG_CONSTRUCTED 未使用. 未使用。 TDN_VERIFICATION_CLICKED 1,复选框处于选中状态,0;未启用。 未使用。 TDN_HELP 未使用。 未使用。 TDN_EXPANDO_BUTTON_CLICKED 0,展开区域处于折叠状态;非零,外接文本显示。 未使用。 功能常量名 作用 S_OK 对于TaskDialogCallbackProc处理完成后返回,并把执行权交回TaskDialog S_FALSE 对于TaskDialogCallbackProc处理完成后,不把执行权交回TaskDialog 备注 TaskDialogCallback 处理的默认实现特定消息然后调用适当在 CTaskDialog类选件的方法。 例如,在响应 TDN_BUTTON_CLICKED 消息,TaskDialogCallback 调用 CTaskDialog::OnCommandControlClick。 wParam 和 lParam 的值取决于特定生成的消息。 可以为或这两个值可以为空。 下表列出了支持的默认值通知,以及 wParam 和 lParam 的值表示。 如果您具有派生类中重写此方法,则应实现每个消息的回调代码在下表中。 效果 解释: TaskDialog中设置了回调事件“TaskDialogCallbackProc2”,然后取出进度条句柄,修改进度条的进度。 更多例子: 链接测试 月历测试
《Linux多线程服务端编程:使用muduo C++网络库》主要讲述采用现代C++在x86-64 Linux上编写多线程TCP网络服务程序的主流常规技术,重点讲解一种适应性较强的多线程服务器的编程模型,即one loop per thread。 目 录 第1部分C++ 多线程系统编程 第1章线程安全的对象生命期管理3 1.1当析构函数遇到多线程. . . . . . . . . . . . . . . . .. . . . . . . . . . . 3 1.1.1线程安全的定义. . . . . . . . . . . . . . . . .. . . . . . . . . . . 4 1.1.2MutexLock 与MutexLockGuard. . . . . . . . . . . . . . . . . . . . 4 1.1.3一个线程安全的Counter 示例.. . . . . . . . . . . . . . . . . . . 4 1.2对象的创建很简单. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 5 1.3销毁太难. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 7 1.3.1mutex 不是办法. . . . . . . . . . . . . . . . . . . .. . . . . . . . 7 1.3.2作为数据成员的mutex 不能保护析构.. . . . . . . . . . . . . . 8 1.4线程安全的Observer 有多难.. . . . . . . . . . . . . . . . . . . . . . . . 8 1.5原始指针有何不妥. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 11 1.6神器shared_ptr/weak_ptr . . . . . . . . . .. . . . . . . . . . . . . . . . 13 1.7插曲:系统地避免各种指针错误. . . . . . . . . . . . . . . . .. . . . . . 14 1.8应用到Observer 上.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.9再论shared_ptr 的线程安全.. . . . . . . . . . . . . . . . . . . . . . . . 17 1.10shared_ptr 技术与陷阱. . . .. . . . . . . . . . . . . . . . . . . . . . . . 19 1.11对象池. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . 21 1.11.1enable_shared_from_this . . . . . . . . . . . . . . . . . . . . . . 23 1.11.2弱回调. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 24 1.12替代方案. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 26 1.13心得与小结. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . 26 1.14Observer 之谬. . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 第2章线程同步精要 2.1互斥器(mutex). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.1.1只使用非递归的mutex . . . . . . . . . . . . . .. . . . . . . . . . 33 2.1.2死锁. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 35 2.2条件变量(condition variable). . . . . . . . . .

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值