从 C 文件调用rrd_create



我正在尝试从我在CLion(在ubuntu上(中的项目中调用rrd func,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?

In 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})

相关内容

  • 没有找到相关文章

最新更新