当前位置:  开发笔记 > 运维 > 正文

如何正确引用GNU readline库来扫描终端输入?

如何解决《如何正确引用GNUreadline库来扫描终端输入?》经验,为你挑选了2个好方法。

我正在尝试编译在GNU readline中使用以下内容的C代码.

#include ;
#include ;

我已经尝试将<>更改为""并使用和不使用-lreadline选项进行编译.似乎没什么用.在gcc下编译时没有-lreadline导致在编译时生成以下内容(详细):

Reading specs from /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --prefix=/software/gcc-3.4.6-0/pkg --disable-dependency-tracking --localstatedir=/var --disable-nls --program-suffix=34 --enable-shared --enable-version-specific-runtime-libs
Thread model: posix
gcc version 3.4.6
 /software/gcc-3.4.6-0/pkg/libexec/gcc/i386-unknown-freebsd6.1/3.4.6/cc1 -quiet -v myshell.c -quiet -dumpbase myshell.c -auxbase myshell -version -o /var/tmp//ccVSq3jQ.s
ignoring nonexistent directory "/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/../../../../i386-unknown-freebsd6.1/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /software/gcc-3.4.6-0/pkg/include
 /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/include
 /usr/include
End of search list.
GNU C version 3.4.6 (i386-unknown-freebsd6.1)
        compiled by GNU C version 3.4.6.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129976
 as -o /var/tmp//ccl1Jaqk.o /var/tmp//ccVSq3jQ.s
 /software/gcc-3.4.6-0/pkg/libexec/gcc/i386-unknown-freebsd6.1/3.4.6/collect2 -V -dynamic-linker /libexec/ld-elf.so.1 -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1 -o a /usr/lib/crt1.o /usr/lib/crti.o /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/crtbegin.o -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6 -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/../../.. /var/tmp//ccl1Jaqk.o -lreadline -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/crtend.o /usr/lib/crtn.o
/usr/bin/ld: cannot find -lreadline
GNU ld version 2.15 [FreeBSD] 2004-05-23
  Supported emulations:
   elf_i386_fbsd
collect2: ld returned 1 exit status

这是在没有-lreadline选项的情况下进行编译时的输出.

/var/tmp//ccNnucSC.o(.text+0x4f): In function `main':
: undefined reference to `readline'
collect2: ld returned 1 exit status

到目前为止,我无法解决此错误.我在代码中或在调用gcc时缺少什么?



1> XBigTK13X..:

在UNIX下编译时,我发现正确引用GNU readline库需要以下内容:

gcc code.c -L/usr/local/lib -I/usr/local/include -lreadline

这可确保编译器在编译和链接期间查找readline目录和文件.



2> Niki Yoshiuc..:

听起来你没有安装libreadline开发库.在Debian(包括FreeBSD端口)上,库位于/ lib中,开发库(您将链接到的)位于/ usr/lib中.

此外,你的包括后你有分号,你不应该有.

推荐阅读
凹凸曼00威威_694
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有