简体   繁体   English

Botan AutoSeded_RNG 无法初始化,未知参考,尽管库已正确链接

[英]Botan AutoSeeded_RNG can not be initialized, unknown reference, although libs are correctly linked

I simply try to initialize the Botan AutoSeeded_RNG but it fails because of a bad reference.我只是尝试初始化 Botan AutoSeded_RNG,但由于参考错误而失败。 I just wanted to test if i can initialize any kind of botan RNG, corse i have trouble with it in another project.我只是想测试我是否可以初始化任何类型的植物 RNG,因为我在另一个项目中遇到了麻烦。

I have the correct header included and am linking to the lib of Botan, therefore i don't know, why it can not find the referende.我包含正确的 header 并链接到 Botan 的库,因此我不知道为什么它找不到公投。

Here is my code:这是我的代码:

  1 #include <botan/auto_rng.h>
  2 #include <botan/ecdh.h>
  3 #include <botan/ec_group.h>
  4 #include <botan/pubkey.h>
  5 #include <botan/hex.h>
  6 #include <iostream>
  7
  8 int main() {
  9
 10     Botan::AutoSeeded_RNG rng;
 11
 12     return 0;
 13 }
 14

And here is my output:这是我的 output:

~/projects $ g++ ecdh.cpp -o ecdh -I/usr/local/include/botan-2/ -L/usr/local/lib/
/usr/bin/ld: /tmp/cccPpNuZ.o: in function `main':
ecdh.cpp:(.text+0x18): undefined reference to `Botan::AutoSeeded_RNG::AutoSeeded_RNG(unsigned int)'
/usr/bin/ld: ecdh.cpp:(.text+0x28): undefined reference to `Botan::AutoSeeded_RNG::~AutoSeeded_RNG()'
collect2: error: ld returned 1 exit status

What am i doing wrong?我究竟做错了什么?

Thx for your advice in advance.感谢您提前提供建议。

You are not linking against the botan library.您没有链接到植物库。 The -L <dir> flag only adds the directory to the library search paths, it does not tell g++ to link against any specific library. -L <dir>标志仅将目录添加到库搜索路径,它不会告诉g++链接到任何特定库。 To link against a library, you have to use the -l <lib> parameter.要链接到库,您必须使用-l <lib>参数。 The linker will then search for this library in its library search paths, including the directories passed with -L <dir> .然后 linker 将在其库搜索路径中搜索此库,包括使用-L <dir>传递的目录。

To link against the botan library, you have to find the directory containing the botan library.要链接到 botan 库,您必须找到包含 botan 库的目录。 I understand in your case this is /usr/local/lib/libbotan-2.so .我了解您的情况是/usr/local/lib/libbotan-2.so You would then add the -lbotan-2 parameter to the g++ parameter list.然后将-lbotan-2参数添加到g++参数列表中。 This will make g++ look for libraries called libbotan-2.so in its library search paths.这将使g++在其库搜索路径中查找名为libbotan-2.so的库。 Since you added /usr/local/lib to the library search paths with the -L /usr/local/lib parameter, g++ should then be able to locate the library in this folder.由于您使用-L /usr/local/lib参数将/usr/local/lib添加到库搜索路径,因此g++应该能够在此文件夹中找到库。

Note that additional parameters may be required or are recommended by the botan library for an optimal experience.请注意,植物库可能需要或推荐其他参数以获得最佳体验。 You can find these parameters in a file called botan-2.pc , which should be contained somewhere in your custom installation.您可以在名为botan-2.pc的文件中找到这些参数,该文件应包含在您的自定义安装中的某个位置。 On my system, it contains the following information:在我的系统上,它包含以下信息:

$ cat /usr/lib/pkgconfig/botan-2.pc
prefix=/usr
exec_prefix=${prefix}
libdir=/usr/lib
includedir=${prefix}/include/botan-2

Name: Botan
Description: Crypto and TLS for C++11
Version: 2.15.0

Libs: -L${libdir} -lbotan-2 -fstack-protector -m64 -pthread
Libs.private: -lbz2 -ldl -llzma -lrt -lz
Cflags: -I${includedir}

This information can also be queried directly using the pkg-config command:也可以使用pkg-config命令直接查询此信息:

$ PKG_CONFIG_PATH=/some/path:$PKG_CONFIG_PATH pkg-config --libs --cflags botan-2
-I/usr/include/botan-2 -lbotan-2 -fstack-protector -m64 -pthread

Where /some/path is the directory containing the botan-2.pc .其中/some/path是包含botan-2.pc的目录。 This gives us the recommended compiler and linker flags for the botan library.这为我们提供了 botan 库的推荐编译器和 linker 标志。 We could either copy them to the g++ parameter list manually, or pass them automatically using:我们可以手动将它们复制到 g++ 参数列表中,或者使用以下命令自动传递它们:

g++ $(PKG_CONFIG_PATH=/some/path:$PKG_CONFIG_PATH pkg-config --libs --cflags botan-2) my_program.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM