gpt4 book ai didi

从c文件调用rrd_create

转载 作者:行者123 更新时间:2023-11-30 16:39:00 24 4
gpt4 key购买 nike

我正在尝试从 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?

最佳答案

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

关于从c文件调用rrd_create,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47237310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com