致命错误:blake2.h:没有这样的文件或目录

时间:2019-07-14 00:18:48

标签: c++ hash crypto++

我正在使用RaspberryPi,Crypto ++ 6是apt唯一可用的版本,我不能包含哈希函数库blake2,并且/usr/include/cryptopp/blake2.h不存在,我也尝试安装它是通过github手动安装的,下面是我手动安装的方式,但是仍然无法正常工作,并且include文件夹中也不存在blake.h,我该怎么办?预先谢谢你!

我之所以使用<crypto++/libname.h>是因为我使用的是基于Debian的发行版(拉伸),但是当我尝试<cryptopp/blake.h>时它可以工作,并且这是在我手动安装了库之后,现在又出现了另一个错误,我应该使用crypto ++或cryptopp

/tmp/ccTmS4UQ.o: In function `main':
test.cpp:(.text+0x24): undefined reference to `CryptoPP::BLAKE2b::BLAKE2b(bool, unsigned int)'
/tmp/ccTmS4UQ.o: In function `CryptoPP::BLAKE2b::~BLAKE2b()':
test.cpp:(.text._ZN8CryptoPP7BLAKE2bD2Ev[_ZN8CryptoPP7BLAKE2bD5Ev]+0x74): undefined reference to `vtable for CryptoPP::BLAKE2b'
test.cpp:(.text._ZN8CryptoPP7BLAKE2bD2Ev[_ZN8CryptoPP7BLAKE2bD5Ev]+0x78): undefined reference to `vtable for CryptoPP::BLAKE2b'
collect2: error: ld returned 1 exit status

并且:

uname -a
Linux raspberrypi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux

ldconfig -p | grep crypto++
libcrypto++.so.6 (libc6,hard-float) => /usr/lib/arm-linux-gnueabihf/libcrypto++.so.6
libcrypto++.so (libc6,hard-float) => /usr/lib/arm-linux-gnueabihf/libcrypto++.so

和一个程序

#include <crypto++/cryptlib.h>
#include <crypto++/blake2.h>

#include <iostream>

int main (int argc, char* argv[])
{
    using namespace CryptoPP;
    BLAKE2b hash;   
    std::cout << "Name: " << hash.AlgorithmName() << std::endl;
    std::cout << "Digest size: " << hash.DigestSize() << std::endl;
    std::cout << "Block size: " << hash.BlockSize() << std::endl;

    return 0; 
}

1 个答案:

答案 0 :(得分:0)

我已经卸载了软件包,并通过github手动重新安装  sudo git clone https://github.com/weidai11/cryptopp  cd cryptopp  sudo make  sudo make install

我摆脱了blake2.h缺少的错误,但是我遇到了许多未定义的参考错误,例如(/tmp/cc9AY7g8.o:(.rodata._ZTIN8CryptoPP25MessageAuthenticationCodeE[_ZTIN8CryptoPP25MessageAuthenticationCodeE]+0x18): undefined reference to typeinfo for CryptoPP::HashTransformation)

我正在使用以下shell脚本来整理示例:

g++ -lrt -lpthread -lstdc++ -lcrypto -lcryptopp "$1" \
      "$LIBRARY_DIR/arduPiLoRa.o" \
      "$ARDUPIAPI_DIR/arduPiUART.o" \
      "$ARDUPIAPI_DIR/arduPiUtils.o" \
      "$ARDUPIAPI_DIR/arduPiMultiprotocol.o" \
      "$ARDUPI_DIR/arduPi.o" \
      "$LIBRARY_DIR/ecdh.o" \
      "$LIBRARY_DIR/aes.o" \
      -I"$ARDUPI_DIR" \
      -I"$ARDUPIAPI_DIR" \
      -I"$LIBRARY_DIR" \
      -o "$1_exe" 

但是当我直接使用g++ -o blake2 blake2.cpp -lcryptopp对其进行编译时,未定义的参考错误消失了,并且我成功地对其进行了编译,

我已经更改了shell脚本,现在终于可以了,但是我并没有完全理解它,

g++ -DNDEBUG -g3 -O2 -Wall -Wextra -lrt -lpthread -lstdc++ -lcrypto -lcryptopp -l:libcryptopp.a "$1" \
  "$LIBRARY_DIR/arduPiLoRa.o" \
  "$ARDUPIAPI_DIR/arduPiUART.o" \
  "$ARDUPIAPI_DIR/arduPiUtils.o" \
  "$ARDUPIAPI_DIR/arduPiMultiprotocol.o" \
  "$ARDUPI_DIR/arduPi.o" \
  "$LIBRARY_DIR/ecdh.o" \
  "$LIBRARY_DIR/aes.o" \
  -I"$ARDUPI_DIR" \
  -I"$ARDUPIAPI_DIR" \
  -I"$LIBRARY_DIR" \
  -o "$1_exe" \
  -l:libcryptopp.a