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\n");
24 
25         printf("%-7s %11u %11u %11u %11u %11u %11u\n",
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\n",
35                "Swap:",
36                 mb(swap.total),
37                 mb(swap.used),
38                 mb(swap.free));
39 
40     glibtop_close();
41 
42     return 0;
43 }

目录结构

 

posted @ 2021-01-18 17:17  voh99800  阅读(385)  评论(0编辑  收藏  举报