在Linux下使用clang/gcc设置rocksdb的LIBRARY_PATH

n7taea2i  于 4个月前  发布在  Linux
关注(0)|答案(1)|浏览(37)

我正在尝试将rocksdb构建为共享库,在指定其依赖关系时遇到问题。我想使用bzip 2编译rocksdb,但问题是默认情况下rocksdb在我的系统目录中使用bzip 2共享库,但我希望它使用LIBRARY_PATH中的路径。这是由于优先级吗?我可以克服这个问题吗?我还尝试在执行export LIBRARY_PATH=/home/test之后使用gcc和带有-v标志的clang编译一个简单的c程序
GCC输出:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
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-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v temp.c -quiet -dumpbase temp.c -mtune=generic -march=x86-64 -auxbase temp -version -o /tmp/cc0hqFLg.s
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-36) (x86_64-redhat-linux)
    compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-36), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include
 /usr/local/include
 /usr/include
End of search list.
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-36) (x86_64-redhat-linux)
    compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-36), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 592abcad67b46aec035d56e51f71d007
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccrqa76q.o /tmp/cc0hqFLg.s
GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-34.base.el7
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/test/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/test -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/ccrqa76q.o -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.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o

字符串
clang输出:

clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5
 "/usr/bin/clang" -cc1 -triple x86_64-redhat-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name temp.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.27 -v -resource-dir /usr/bin/../lib/clang/3.4.2 -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/cstore -ferror-limit 19 -fmessage-length 114 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/temp-d8b8da.o -x c temp.c
clang -cc1 version 3.4.2 based upon LLVM 3.4.2 default target x86_64-redhat-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/3.4.2/include
 /usr/include
End of search list.
 "/usr/bin/ld" --hash-style=gnu --no-add-needed --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../.. -L/lib -L/usr/lib /tmp/temp-d8b8da.o -L/home/cstore -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o


我做错了什么?
使用uname的计算机信息-a:Linux 698324 c876 e6 6.5.11-linuxkit #1 SMP PREEMPT Wed Dec 6 17:08:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
clang版本:3.4.2 gcc版本:4.8.5

Edit-1经过大量的谷歌搜索和测试,我发现在Linux中,在编译时,LIBRARY_PATH不会首先搜索共享库,而在Mac OS中,我使用LIBRARY_PATH设置的路径将首先使用。是什么导致了这种行为。在Linux中,我设置的路径将与../lib一起发生,该路径将首先搜索,然后是gcc设置的一些路径,然后是我的实际路径。

示例:$ export LIBRARY_PATH=/home/test ->在使用-v编译程序后,我得到的输出为LIBRARY_PATH=/home/test/../lib::/home/test:。

Edit-2我使用的是rocksdb 5.8版本的make。

sdnqo3pr

sdnqo3pr1#

对于cmake用户:尝试在cmake命令中将-DCMAKE_PREFIX_PATH设置为您的安装目录。
对于RocksDB Makefile用户:尝试在RocksDB make命令中设置EXTRA_CXXFLAGS="-I/path/to/your/custom/include/dir/" EXTRA_LDFLAGS="-L/path/to/your/custom/lib/dir"。此外,在运行二进制文件时在环境中设置LD_LIBRARY_PATH=/path/to/your/custom/lib/dir。如果在链接步骤中设置rpath,则可以跳过设置LD_LIBRARY_PATH

相关问题