c - FreeBSD 上对 sbuf 函数的 undefined reference

标签 c linker clang freebsd undefined-reference

我的 sbuf(9) 发生了什么?

这是我的程序:

#include <sys/types.h>
#include <sys/sbuf.h>
#include <unistd.h>

int main() {
    struct sbuf * sb;
    sb = sbuf_new_auto();
    return 0;
}

当我使用 clang -v test.c 编译我的程序时,我得到:

FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: i386-unknown-freebsd10.3
Thread model: posix
Selected GCC installation: 
 "/usr/bin/clang" -cc1 -triple i386-unknown-freebsd10.3 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -v -resource-dir /usr/bin/../lib/clang/3.4.1 -fdebug-compilation-dir /usr/home/0mp/g/freebsd/contrib/openbsm/bin/bsmconv -ferror-limit 19 -fmessage-length 170 -mstackrealign -fobjc-runtime=gnustep -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/test-fc3a72.o -x c test.c
clang -cc1 version 3.4.1 based upon LLVM 3.4.1 default target i386-unknown-freebsd10.3
ignoring nonexistent directory "/usr/bin/../lib/clang/3.4.1/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/clang/3.4.1
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -m elf_i386_fbsd -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/test-fc3a72.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/tmp/test-fc3a72.o: In function `main':
test.c:(.text+0x3d): undefined reference to `sbuf_new'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

注释

  • 编译器还会向我显示 sbuf 函数的错误和警告,以便它了解 sys/sbuf.h 的外观。
  • 我使用 FreeBSD 10.3 RELEASE i386。

最佳答案

尝试在编译命令中使用 -lsbuf 吗?

关于c - FreeBSD 上对 sbuf 函数的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38022644/

相关文章:

CMake find_package 找不到我的 MinGW libjpeg

c - C中的字符串终止-存储和匹配之间的区别

Lint能否解析头文件的包含路径

c - 编译器决定放入寄存器的变量的运算符地址会发生什么?

python - 如何使用 libclang 的 python 绑定(bind)在 AST 遍历中跳过子树

c - 我的 C 生成文件有什么问题?

linux - 如何在Linux/gcc上创建与pthread和libstdc++静态链接的共享对象?

C winsock2.h WS2_32.lib 链接 undefined reference

c - 如果库中的公开结构发生更改,使用它的应用程序是否必须重新编译?

c++ - 如何在 LLVM 模块中增加全局变量?