【问题标题】:Undefined reference to sbuf functions on FreeBSDFreeBSD 上对 sbuf 函数的未定义引用
【发布时间】:2016-06-24 21:55:27
【问题描述】:

我的 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。

【问题讨论】:

    标签: c linker clang freebsd undefined-reference


    【解决方案1】:

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

    【讨论】:

    • 很遗憾我在手册和 iInternet 上都找不到它。我应该怎么猜?是否有规则或地方可以检查标题是否需要 -labc 选项?
    • 没有什么我可以马上看到的,但一个专业提示:你看到的东西以“未定义的引用”方式失败,而不是你得到你的声明(来自 .h)但仍然缺少定义(lib)。
    • 这是我在网上找到的——你缺少一些-l。但是我找不到 sbuf(9) 的那个。谢谢!
    • 好。现在,我会去 /usr/lib/ 并做字符串来找出丢失的符号在哪里。希望对您有所帮助。
    猜你喜欢
    • 2019-09-05
    • 2011-09-19
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2018-03-07
    • 2021-02-09
    相关资源
    最近更新 更多