当前位置: 代码网 > 服务器>服务器>Linux > C/C++ 跨平台(android/unix/windows)工具库(xlog日志),支持log打印、检测内存泄露

C/C++ 跨平台(android/unix/windows)工具库(xlog日志),支持log打印、检测内存泄露

2024年08月06日 Linux 我要评论
C 通用工具库(xlog 日志库),支持 unix(android/linux)/windows 等平台

简介

这是一个通用c工具库,支持 unix(android)/windows 等平台


组件

  • log

    • logger : logger门面. xlog 和 slog 实现它定义的宏
    • xlog : 支持打印 level/tag/tid/time 这些log头和日志信息
    • slog : 简易log实现,实际上是对printf的二次包装, 只支持打印level/tag和日志信息
  • thread

  • data

  • file

  • memory

    • string : asprintf, stringbuilder, str_params, strlcpy, strlcat, strreplace, strsplit, strtrim, strutf8len
    • allocator : 跟踪和检测heap内存,帮助你提早发现内存泄露和踩内存等问题.
    • mplite : 内存池实现 sqlite’s memsys5 memory subsystem
  • ring_buffer

  • time


编译

  • 常用平台 (windows/linux/android)

    platformonekey deploy buildmanual build
    windowsdeploy_for_windows.bat releasemake_windows.bat win32 release 1
    linuxchmod +x *.sh && ./deploy_for_linux.sh releasechmod +x *.sh && ./make_cross_platform.sh linux m64 release
    androiddeploy_for_android.bat release c++_staticmake_android.bat armeabi-v7a release
  • 其他平台 (交叉编译)

    1. 首先,在 tool/cmake/toolchains 文件夹下写cmake交叉编译规则文件:
    set(unix true cache bool "")
    set(cmake_system_name linux) # this one is important
    set(cmake_system_version 1)  # this one not so much
    # tell the cmake script what the platform name is, must setup this for cross compile
    set(platform hisi)           # important: tell script the platform name
    
    set(cross_toolchain_dir "/root/toolchains/hisi-linux/x86-arm/arm-himix100-linux")
    set(cross_toolchain_path_prefix "${cross_toolchain_dir}/bin/arm-himix100-linux-")
    message(status "current cross_toolchain_path_prefix is => ${cross_toolchain_path_prefix}")
    
    #set compiler location
    set(cmake_c_compiler "${cross_toolchain_path_prefix}gcc")
    set(cmake_cxx_compiler "${cross_toolchain_path_prefix}g++")
    set(cmake_ar "${cross_toolchain_path_prefix}ar")
    set(cmake_linker "${cross_toolchain_path_prefix}ld")
    set(cmake_ranlib "${cross_toolchain_path_prefix}ranlib")
    set(cmake_strip "${cross_toolchain_path_prefix}strip")
    
    set(cmake_find_root_path  ${cross_toolchain_dir})
    # sysroot.
    set(cmake_sysroot "${cross_toolchain_dir}/sysroot")
    # search for programs in the build host directories
    set(cmake_find_root_path_mode_program never)
    # for libraries and headers in the target directories
    set(cmake_find_root_path_mode_library only)
    set(cmake_find_root_path_mode_include only)
    
    set(platform_common_flags " -fpic")
    string(append cmake_c_flags          "${platform_common_flags}")
    string(append cmake_cxx_flags        "${platform_common_flags}")
    string(append cmake_exe_linker_flags "${platform_common_flags} -fpie")
    add_definitions(-d_lcu_not_support_pthread_setname) # custom compile definitions
    
    1. 执行 cmake 命令编译:
    ./make_cross_platform.sh hisi release
    
    cmake -h. -b./build_abcd -dbuild_static_libs=on -dbuild_shared_libs=off -dbuild_demo=off -dcmake_try_compile_target_type=static_library -dcmake_toolchain_file=./cmake/toolchains/abcd.toolchain.cmake
    cmake --build ./build_abcd --config release --target lcu_static
    

使用

示例

许可证

联系方式


更新日志

  • 1.8.0

  • 1.7.0

  • 1.6.0

  • 1.5.6

  • 1.5.5

  • 1.5.3

  • 1.5.2

  • 1.4.1

  • 1.0.0 ~ 1.4.0

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com