【问题标题】:Can't link BOTAN library with eclipse无法将 BOTAN 库与 eclipse 链接
【发布时间】:2012-06-07 19:41:38
【问题描述】:

我已经安装并构建了BOTAN 密码库。

一切似乎都已正确安装,因为我在 /usr/local/lib 目录中有以下条目:

-rw-r--r-- 1 root root   7676350 2012-06-03 11:01 libbotan-1.10.a
lrwxrwxrwx 1 root root        20 2012-06-03 11:01 libbotan-1.10.so -> libbotan-1.10.so.0.1
lrwxrwxrwx 1 root root        20 2012-06-03 11:01 libbotan-1.10.so.0 -> libbotan-1.10.so.0.1
-rwxr-xr-x 1 root root   3396354 2012-06-03 11:01 libbotan-1.10.so.0.1

/usr/local/include 中也有一个:

drwxr-xr-x  3 root root  4096 2012-06-03 11:01 botan-1.10

最终我设法将这些库包含在我的程序的主体中,并且没有错误地编写代码。

但是,在构建我的项目(在 Eclipse Indigo 上)时,我在控制台上得到以下输出,红色 stderr 时尚:

error while loading shared libraries: libbotan-1.10.so.0: cannot open shared object file: No such file or directory

我尝试执行的代码如下:

try
{
    cout << "In try" << endl;
    Botan::LibraryInitializer init;
}catch(std::exception& e)
{
    cout << "In catch" << endl;
    cerr << e.what() << endl;
}

我有以下疑惑:

  1. 是链接器的问题吗? (如果是,为什么不是链接器抛出错误,而是标准错误?)

  2. 如果没有,我怎样才能让我的程序找到实际存在的libbotan-1.10.so.0 文件? (/usr/local/lib)。

请注意,我的环境变量 $LD_LIBRARY_PATH 当前已设置,并且具有以下值:

$> echo $LD_LIBRARY_PATH
$> /usr/local/lib/

编译器命令行:

调用:GCC C++ 编译器

g++ -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -O3 -g3 -Wall -c -fmessage-length=0 -std=c++0x -v -MMD -MP -MF"mainOobClient.d" -MT"mainOobClient.d" -o "mainOobClient.o" "../mainOobClient.cpp"

g++ -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -O3 -g3 -Wall -c -fmessage-length=0 -std=c++0x -v -MMD -MP -MF"oobClientClass.d" -MT"oobClientClass.d" -o "oobClientClass.o" "../oobClientClass.cpp"

调用:GCC C++ 链接器

g++ -L/usr/local/lib -o  "MTVS_oobClient"  ./mainOobClient.o ./oobClientClass.o   -lbotan-1.10

完成构建输出:

Build of configuration Debug for project MTVS_oobClient

make all 
Building file: ../mainOobClient.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -O3 -g3 -Wall -c -fmessage-length=0 -std=c++0x -v -MMD -MP -MF"mainOobClient.d" -MT"mainOobClient.d" -o "mainOobClient.o" "../mainOobClient.cpp"
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) 
Finished building: ../mainOobClient.cpp

Building file: ../oobClientClass.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -O3 -g3 -Wall -c -fmessage-length=0 -std=c++0x -v -MMD -MP -MF"oobClientClass.d" -MT"oobClientClass.d" -o "oobClientClass.o" "../oobClientClass.cpp"
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFmainOobClient.d' '-MTmainOobClient.d' '-o' 'mainOobClient.o' '-shared-libgcc' '-mtune=generic' '-march=i686'
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/cc1plus -quiet -v -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -MMD mainOobClient.d -MFmainOobClient.d -MP -MTmainOobClient.d -MQ mainOobClient.o -dD -D_GNU_SOURCE ../mainOobClient.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase mainOobClient.cpp -mtune=generic -march=i686 -auxbase-strip mainOobClient.o -g3 -O3 -Wall -std=c++0x -version -fmessage-length=0 -fstack-protector -o /tmp/ccLIYQkV.s
Finished building: ../oobClientClass.cpp
GNU C++ (Ubuntu/Linaro 4.5.2-8ubuntu4) version 4.5.2 (i686-linux-gnu)

Building target: MTVS_oobClient
Invoking: GCC C++ Linker
g++  ./mainOobClient.o ./oobClientClass.o   -lbotan-1.10 -L/usr/local/lib -o  "MTVS_oobClient"
    compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory "/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../../../i686-linux-gnu/include"
ignoring duplicate directory "/usr/include/c++/4.5.2"
  as it is a non-system directory that duplicates a system directory
Finished building target: MTVS_oobClient
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/botan-1.10

 /usr/include/c++/4.5
 /usr/include/c++/4.5/i686-linux-gnu
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.5.2-8ubuntu4) version 4.5.2 (i686-linux-gnu)
    compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0c5cb630517b5952f4898dfa56d7e8e5
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFmainOobClient.d' '-MTmainOobClient.d' '-o' 'mainOobClient.o' '-shared-libgcc' '-mtune=generic' '-march=i686'
 as -V -Qy --32 -o mainOobClient.o /tmp/ccLIYQkV.s
GNU assembler version 2.21.0 (i686-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.21.0.20110327
COMPILER_PATH=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../:/lib/:/usr/lib/:/usr/lib/i386-linux-gnu/
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFmainOobClient.d' '-MTmainOobClient.d' '-o' 'mainOobClient.o' '-shared-libgcc' '-mtune=generic' '-march=i686'
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) 
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFoobClientClass.d' '-MToobClientClass.d' '-o' 'oobClientClass.o' '-shared-libgcc' '-mtune=generic' '-march=i686'
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/cc1plus -quiet -v -I/usr/include/c++/4.5.2 -I/usr/local/include/botan-1.10 -MMD oobClientClass.d -MFoobClientClass.d -MP -MToobClientClass.d -MQ oobClientClass.o -dD -D_GNU_SOURCE ../oobClientClass.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase oobClientClass.cpp -mtune=generic -march=i686 -auxbase-strip oobClientClass.o -g3 -O3 -Wall -std=c++0x -version -fmessage-length=0 -fstack-protector -o /tmp/ccTuqeWw.s
GNU C++ (Ubuntu/Linaro 4.5.2-8ubuntu4) version 4.5.2 (i686-linux-gnu)
    compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory "/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../../../i686-linux-gnu/include"
ignoring duplicate directory "/usr/include/c++/4.5.2"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/botan-1.10
 /usr/include/c++/4.5
 /usr/include/c++/4.5/i686-linux-gnu
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include
 /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.5.2-8ubuntu4) version 4.5.2 (i686-linux-gnu)
    compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0c5cb630517b5952f4898dfa56d7e8e5
../oobClientClass.cpp: In member function ‘void oobClientClass::authenticateTransaction()’:
../oobClientClass.cpp:126:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
../oobClientClass.cpp:164:63: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
../oobClientClass.cpp:59:6: warning: ‘confirmationChoice’ may be used uninitialized in this function
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFoobClientClass.d' '-MToobClientClass.d' '-o' 'oobClientClass.o' '-shared-libgcc' '-mtune=generic' '-march=i686'
 as -V -Qy --32 -o oobClientClass.o /tmp/ccTuqeWw.s
GNU assembler version 2.21.0 (i686-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.21.0.20110327
COMPILER_PATH=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../:/lib/:/usr/lib/:/usr/lib/i386-linux-gnu/
COLLECT_GCC_OPTIONS='-I/usr/include/c++/4.5.2' '-I/usr/local/include/botan-1.10' '-O3' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++0x' '-v' '-MMD' '-MP' '-MFoobClientClass.d' '-MToobClientClass.d' '-o' 'oobClientClass.o' '-shared-libgcc' '-mtune=generic' '-march=i686'

**** Build Finished ****

【问题讨论】:

  • eclipse 正在执行的实际编译器命令是什么?
  • @juanchopanza - 添加部分...感谢让我注意到 ;)
  • 您可以尝试将其输入控制台,但使用-lbotan,即没有版本号吗?
  • @juanchopanza - 这是我首先想到的,但在这种情况下,链接器会出错:g++ -L/usr/local/lib -o "MTVS_oobClient" ./mainOobClient.o ./oobClientClass.o -lbotan /usr/bin/ld: cannot find -lbotan collect2: ld returned 1 exit status make: *** [MTVS_oobClient] Error 1
  • 啊当然,版本是名称的一部分。很抱歉,这是一个无意义的建议。

标签: c++ eclipse linker g++ shared-libraries


【解决方案1】:

错误出现在运行时。您需要在构建时指定二进制文件的 rpath - 您拥有的位置:

-L/usr/local/lib

你还需要:

-Wl,-rpath=/usr/local/lib

这指示ld 在运行时尝试查找库时使用此路径。您的LD_LIBRARY_PATH 可能已被 Eclipse 的启动器覆盖,这就是未使用该变量的原因。

替代方案:

确保/usr/local/lib/etc/ld.so.conf中,并且在安装库后ldconfig已经运行。

使用命令行链接到 .a:

g++ -o  "MTVS_oobClient"  ./mainOobClient.o ./oobClientClass.o -L/usr/local/lib -Wl,-Bstatic -lbotan-1.10 -Wl,-Bdynamic

或使用:

g++ -o  "MTVS_oobClient"  ./mainOobClient.o ./oobClientClass.o /usr/local/lib/libbotan-1.10.a

...两者应该具有相同的效果

【讨论】:

    【解决方案2】:

    由于程序构建正确结束,很明显这是一个运行时问题,因为程序找不到共享库。

    感谢另一个SO question,我寻找其他有相同运行时问题的人并找到了解决方案(我将简要总结一下)。

    我所做的是构建动态链接的可执行文件,它希望在执行时链接到 libbotan-1.10.so.0。构建阶段的链接是使用命令行选项 -L/usr/local/lib 完成的。

    有几个选项可以使botan(或任何其他库)在运行时可用:

    • /etc/ld.so.conf(或/lib/usr/lib)中列出的目录中创建指向botan的符号链接
    • botan复制到/etc/ld.so.conf(或/lib/usr/lib)中列出的目录(默认)
    • 将包含botan的目录添加到/etc/ld.so.conf
    • 在运行可执行文件之前设置LD_LIBRARY_PATH=/usr/local/lib
    • 静态重新编译程序。 (它会起作用,但不要打扰。)

    在前 3 个中的任何一个之后,重新运行 ldconfig,以便更新链接器缓存。 (然后您可以运行ldconfig -v 来验证它是否可解析。)

    请注意,这些不是步骤,而是选项。你只需要做其中之一。

    使用ldconfig 更新链接器缓存使其对我有用。

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2019-01-31
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多