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

时间:2018-12-07 12:41:08

标签: c++ gcc static-libraries crypto++

我已从官方网站下载了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

所以我开始怀疑自己是否做错了什么,但是当我检查带有静态库的代码示例时,一切似乎都很好。

请帮助。

1 个答案:

答案 0 :(得分:0)

基于:

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