未定义对 'function' 的引用,但包含 header

Undefined reference to 'function' yet the header is included

我正在玩 ci20 和 flowcloud。我已经下载了他们的 c library/sdk 并包含了 header.

程序很简单:

#include <stdio.h>
#include <stdbool.h>
#include <flow/flowcore.h>

int main (int argc, char*argv[])
{
    printf("hello");
    if(FlowCore_Initialise()) printf("init");
    return (0);
}

但是在编译时 gcc -Wall test.c -o hello 我得到这个错误:

/tmp/cch4kocL.o: In function `main':
test.c:(.text+0x40): undefined reference to `FlowCore_Initialise'
collect2: error: ld returned 1 exit status

我不是 100% 确定这里发生了什么。

您收到 linker 错误。使用 gcc 编译时,除了使用正确的 #include 之外,还需要指定要 link 的库。

用gcc编译的语法是

$ gcc [options] [source files] [object files] [-Ldir] -llibname [-o outfile]

如您所见,您可以通过将 -l<name> 添加到命令字符串来 link 库。