本文介绍了加载共享库时出错,无法打开共享库文件:无此类文件或目录(hiredis)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于编写C程序的Alpha阶段,该程序在后端使用Redis.

I'm in the alpha stages of writing a C program which uses redis on the back end.

我尝试构建/安装hiredis(make&& sudo make install)并运行测试(大部分通过),但是在尝试构建 example.c 程序,我收到一个错误,找不到hiredis.h.

I've tried building/installing hiredis (make && sudo make install) and running the test (which pass mostly) but when trying to build the example.c program i get an error that hiredis.h couldn't be found.

在命令行上使用以下命令构建:gcc -v example.c -lhiredis -I/usr/local/include/hiredis/

Building on the command line with: gcc -v example.c -l hiredis -I /usr/local/include/hiredis/

我尝试过的事情:

  1. pkg-info hiredis返回0
  2. 通过(make&& ./hiredis-test&& sudo make)和(make clean)卸载/重新安装
  3. 在hireddis.c和hireddis.h所在的目录中构建example.c(仍然没有此类文件或目录)
  4. gcc -v example.c -lhiredis -I/usr/local/include/hiredis/(以及此方法的其他变体)

一切都没有运气.

我猜我没有为gcc正确链接程序,但是文档中没有任何构建示例.

I'm guessing I'm not linking the programs correctly for gcc but the documentation doesn't have any build examples.

我在做什么让我不能使用hiredis构建此代码(或任何代码)?

确切的输出是...

     Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic'
 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1 -quiet -v -I /usr/local/include/hiredis/ example.c -quiet -dumpbase example.c -mtune=generic -auxbase example -version -o /tmp/ccWP2etT.s
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/hiredis/
 /usr/local/include
 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include
 /usr/include
End of search list.
GNU C (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-16) (x86_64-redhat-linux)
        compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-16), GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8fd7a5b48f606b047c876a297c82f28e
COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic'
 as -V -Qy -o /tmp/ccnscL6h.o /tmp/ccWP2etT.s
GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version version 2.20.51.0.2-5.43.el6 20100205
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic'
 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. /tmp/ccnscL6h.o -lhiredis -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o

哪个产生a.out.尝试运行该程序时.我收到以下错误.

Which produces an a.out. When trying to run that program. I get the following error.

./a.out: error while loading shared libraries: libhiredis.so.0.13: cannot open shared object file: No such file or directory

推荐答案

问题是libhiredis不在ldconfig路径中.尽管构建过程是正确的,但它将所有内容都复制到了正确的目录ldconfig中,而不知道其位置.

The problem was the libhiredis wasn't in the ldconfig path. While the build process was correct and it copied everything to the correct directory ldconfig did not know about its location.

您可以使用 ldconfig -p 查看当前知道的所有库ldconfig.

You can use ldconfig -p to see all library ldconfig currently know about.

您可以使用以下方式将路径添加到ldconfig中:

You can add the path to ldconfig with

sudo echo"/usr/local/lib">/etc/ld.so.conf.d/local.conf

&

sudo ldconfig

这篇关于加载共享库时出错,无法打开共享库文件:无此类文件或目录(hiredis)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 14:55