zoukankan      html  css  js  c++  java
  • cpp 使用glib libgtop 第三方库编译记录

    ..

    Cmakelist.txt

     1 project(umsl)
     2 
     3 
     4 
     5 set(CMAKE_CXX_STANDARD 98)
     6 
     7 
     8 
     9 # include_directories("/usr/include/libgtop-2.0","/usr/include/glib-2.0",
    10 
    11 # "/usr/lib/x86_64-linux-gnu/glib-2.0/include",
    12 
    13 # )
    14 
    15 
    16 
    17 include_directories(/usr/include/libgtop-2.0)
    18 
    19 include_directories(/usr/include/glib-2.0)
    20 
    21 include_directories(/usr/lib/x86_64-linux-gnu/glib-2.0/include)
    22 
    23 # include_directories()
    24 
    25 # include_directories()
    26 
    27 # include_directories()
    28 
    29 
    30 
    31 #add_executable(dma_alloc main.cpp dma_request/dma_req.cpp dma_request/dma_req.h thread_m/process_fork.cpp thread_m/process_fork.h)
    32 
    33 add_executable(umsl main.cpp )
    34 
    35 
    36 
    37 target_link_libraries(umsl gtop-2.0)
    38 
    39 target_link_libraries(umsl glib-2.0)
    40 
    41 #cc main.cpp -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0  -I/usr/include/libgtop-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtop-2.0 -lglib-2.0  -o main

    编译命令

     1 uos@uos-PC:~/umsl$ pkg-config --cflags --libs glib-2.0
     2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0
     3 uos@uos-PC:~/umsl$ ls /usr/include/libgtop-2.0/
     4 glibtop  glibtop.h  glibtop_machine.h  glibtop_server.h  libgtopconfig.h
     5 uos@uos-PC:~/umsl$ pkg-config --cflags --libs libgtop-2.0
     6 -I/usr/include/libgtop-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtop-2.0 -lglib-2.0
     7 uos@uos-PC:~/umsl$ cc main.cpp -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0  -I/usr/include/libgtop-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtop-2.0 -lglib-2.0  -o main
     8 uos@uos-PC:~/umsl$ ls                                                                                                                                                                                           build  CMakeLists.txt  dma_request  main  main.cpp  thread_m  util
     9 uos@uos-PC:~/umsl$ ./main
    10               total        used        free      shared  buff/cache   available
    11 Mem:           2978        1527         313         103        1137        1054
    12 Swap:          3070         173        2897

    main.cpp

     1 #include <glibtop.h>
     2 #include <glibtop/mem.h>
     3 #include <glibtop/swap.h>
     4 
     5 #include <glib.h>
     6 #include <unistd.h>
     7 
     8 static unsigned mb(guint64 n)
     9 {
    10         return n >> 20;
    11 }
    12 
    13 int main(int argc, char **argv)
    14 {
    15         glibtop_mem mem;
    16         glibtop_swap swap;
    17 
    18     glibtop_init();
    19 
    20         glibtop_get_mem(&mem);
    21         glibtop_get_swap(&swap);
    22 
    23         printf("              total        used        free      shared  buff/cache   available
    ");
    24 
    25         printf("%-7s %11u %11u %11u %11u %11u %11u
    ",
    26                "Mem:",
    27                 mb(mem.total),
    28                 mb(mem.used - mem.buffer - mem.cached),
    29                 mb(mem.free),
    30                 mb(mem.shared),
    31                 mb(mem.buffer + mem.cached),
    32                 mb(mem.total - mem.user));
    33 
    34         printf("%-7s %11u %11u %11u
    ",
    35                "Swap:",
    36                 mb(swap.total),
    37                 mb(swap.used),
    38                 mb(swap.free));
    39 
    40     glibtop_close();
    41 
    42     return 0;
    43 }

    目录结构

  • 相关阅读:
    电路开发软件积累
    .NET移动开发环境搭建
    Microsoft SQL Server Express各版本对比
    .NET IL指令速查表
    C#访问加密的SQLite数据库
    C#中时间计算方法汇总
    最佳C/C++编辑器 source insight3
    常用PHP框架收集
    CSS 中文字体的英文名称 (simhei, simsun) 宋体 微软雅黑等
    Windows下Java JDK8配置环境变量
  • 原文地址:https://www.cnblogs.com/eiguleo/p/14293718.html
Copyright © 2011-2022 走看看