C SDK 概述
C 版本没有类。
安装
Windows 用的包是 darra-ai-core-windows-x64.zip。用 MSVC 编译时要加 /utf-8。
cl /utf-8 /Fe:my_app.exe main.c DarraAI.Core.lib /I include
Linux x64 / ARM64 用对应 tar.gz。
gcc -o my_app main.c -I include -L. -ldarraai_core -Wl,-rpath,'$ORIGIN'
add_executable(my_app main.c)
target_include_directories(my_app PRIVATE ${SDK_PATH}/include)
target_link_libraries(my_app PRIVATE DarraAI.Core)
在 Linux 上,把链接名 DarraAI.Core 换成 darraai_core 就行。
快速开始
用 memset 把 config 清零即全用默认值。
#include <stdio.h>
#include <string.h>
#include "darra_model.h"
int main(void) {
darra_model_config cfg; darra_model* h = NULL; char* json = NULL;
int32_t rc;
memset(&cfg, 0, sizeof(cfg));
rc = darra_model_create("model.darmodel", &cfg, &h);
if (rc != 0) return rc;
if (!darra_model_open(h, NULL)) return 1;
rc = darra_model_infer_file(h, "photo.jpg", &json);
if (rc == 0) printf("%s\n", json);
else printf("%s\n", darra_model_last_error(h));
if (json) darra_string_free(json);
darra_model_close(h);
return rc;
}
错误码
错误统一按返回码判断(0 成功),不罗列码值。
失败时具体原因看 darra_model_last_error(h),类别看 darra_model_last_error_category(h)(0 无失败 / 1 环境缺包 / 2 输入数据)。
版本兼容
| 项目 | 要求 |
|---|---|
| 操作系统 | Windows x64 / Linux x86_64 / Linux ARM64(RK3588) |
| 编译器 | MSVC(/utf-8)/ GCC / Clang,C11 或更高 |
| 运行库 | Windows:DarraAI.Core.dll;Linux:libCore.so。都要放在运行目录 |
| 模型 | 加密 .darmodel,或明文 .onnx / .pdmodel / TorchScript 归档 .pt / .pth |