从c文件中调用rrd_create

时间:2017-11-11 11:19:00

标签: c ubuntu clion rrdtool

我正在尝试从我在CLion的项目中调用rrd func(在ubuntu上),rrd.h在/ usr / include /中。

我的代码:

#include <stdio.h>
#include <rrd.h>

int main() {
    size_t argc = 6;
    char *argv[] = {
            "test.rrd",
            "--start",
            "920804400",
            "DS:speed:COUNTER:600:U:U",
            "RRA:AVERAGE:0.5:1:24",
            "RRA:AVERAGE:0.5:6:10"
    };
    rrd_create(argc, argv);
    return 0;
}

的CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(rddtool)

set(CMAKE_C_STANDARD 11)

set(SOURCE_FILES main.c /usr/include/rrd.h)
add_executable(rddtool ${SOURCE_FILES})

消息构建:

Scanning dependencies of target rddtool
[ 50%] Building C object CMakeFiles/rddtool.dir/main.c.o
[100%] Linking C executable rddtool
CMakeFiles/rddtool.dir/main.c.o: In function `main':
/home/parallels/CLionProjects/rddtool/main.c:14: undefined reference to `rrd_create'
collect2: error: ld returned 1 exit status
CMakeFiles/rddtool.dir/build.make:94: recipe for target 'rddtool' failed
make[3]: *** [rddtool] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/rddtool.dir/all' failed
make[2]: *** [CMakeFiles/rddtool.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/rddtool.dir/rule' failed
make[1]: *** [CMakeFiles/rddtool.dir/rule] Error 2
Makefile:118: recipe for target 'rddtool' failed
make: *** [rddtool] Error 2

我应该如何调用rrd_create?

1 个答案:

答案 0 :(得分:0)

在CMakeLists.txt中:

cmake_minimum_required(VERSION 3.8)
project(rddtool)

set(CMAKE_C_STANDARD 11)

set(SOURCE_FILES main.c)

find_library(RRD_LIBRARY librrd.so HINTS /usr/lib/x86_64-linux-gnu)

add_executable(rddtool ${SOURCE_FILES})

target_link_libraries(rddtool PUBLIC ${RRD_LIBRARY})