gcc 无法编译,错误:加密库.h:没有这样的文件或目录

nqwrtyyt  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(306)

我已经从官方网站下载了Crypto++ 7.0.0,构建了一个静态库,包括cryptlib头:

#include "cryptlib.h"

当我试图用以下代码编译程序时:

gcc main.cpp ./cryptopp700/libcryptopp.a

它向我抛出这样的错误:

main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
 #include "cryptlib.h"
          ^~~~~~~~~~~~
compilation terminated.

我也试探着:

-L. -llibcryptopp //while moving libcryptopp.a to the same directory main.cpp is
-L./cryptopp700 -llibcryptopp

所以我开始怀疑我是否做错了什么,但是当我用静态库检查代码示例时,一切似乎都很好。
救命啊

dffbzjpn

dffbzjpn1#

依据:

main.cpp:2:10: fatal error: cryptlib.h: No such file or directory

还有:

gcc main.cpp ./cryptopp700/libcryptopp.a

您的目录结构如下所示:

+- Project Folder
  |
  +- main.cpp
  |
  +- cryptopp700
    |
    +- cryltib.h
    +- ...
    +- libcryptopp.a

您应该只需要将cryptopp700/添加到包含头搜索路径中,并使用-I

g++ main.cpp -I ./cryptopp700 ./cryptopp700/libcryptopp.a

请注意,您还应该使用***g++***(C++编译器),而不是***gcc***(C编译器)。
您也可以在建置程式库之后安装程式库。预设会安装到/usr/local中,其中包含:

skylake:cryptopp$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors

您可以使用PREFIX安装到其他位置:

skylake:cryptopp$ sudo make install PREFIX=/opt/local
install -m 644 *.h /opt/local/include/cryptopp
install -m 644 libcryptopp.a /opt/local/lib
install cryptest.exe /opt/local/bin
install -m 644 TestData/*.dat /opt/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /opt/local/share/cryptopp/TestVectors

然后,您可以将编译和链接命令更改为类似以下内容:

g++ main.cpp -I /usr/local/include/cryptopp -o main.exe /usr/local/lib/libcryptopp.a

在安装完如下所示的程序后,我通常会告诉大家运行自检程序。不幸的是,如果你只做了一个make -j 4或类似的程序,那么自检程序就不会工作。

$ make -j 4
...

$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors

下面是您将得到的错误:

skylake:cryptopp$ cd /opt/local/bin/
skylake:bin$ ./cryptest.exe v
Using seed: 1544189072

Testing Settings...

passed:  Your machine is little endian.
passed:  Aligned data access.
passed:  sizeof(byte) == 1
passed:  sizeof(word16) == 2
passed:  sizeof(word32) == 4
passed:  sizeof(word64) == 8
passed:  sizeof(word128) == 16
passed:  sizeof(hword) == 4, sizeof(word) == 8, sizeof(dword) == 16
passed:  cacheLineSize == 64
hasSSE2 == 1, hasSSSE3 == 1, hasSSE4.1 == 1, hasSSE4.2 == 1, hasAVX == 1, hasAVX2 == 1, hasAESNI == 1, hasCLMUL == 1, hasRDRAND == 1, hasRDSEED == 1, hasSHA == 0, isP4 == 0
...

SHA validation suite running...

Exception caught: Can not open file TestVectors/sha.txt for reading

我的想法是事情应该“只是为你工作”。你不应该担心CRYPTOPP_DATA_DIR的一个常见的情况。你当然不应该有RTFM使常见的情况下工作。这告诉我有一个缺陷,在我们的工程过程。
我们现在要解决这个问题:第760期,Make self-tests run after install by a typical user

nkkqxpd9

nkkqxpd92#

对我来说,安装开发crypt库解决了这个问题:

apt-get install libcrypt-devel

相关问题