I've downloaded Crypto++ 7.0.0 from the official site, build a static library out of it, included cryptlib header with:
#include "cryptlib.h"
and when I try to compile my program with:
gcc main.cpp ./cryptopp700/libcryptopp.a
it throws at me errors like this:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
#include "cryptlib.h"
^~~~~~~~~~~~
compilation terminated.
I also tried with:
-L. -llibcryptopp //while moving libcryptopp.a to the same directory main.cpp is
-L./cryptopp700 -llibcryptopp
so I started wondering if I was doing something wrong, but as I was checking out code examples with static libraries, everything seemed to be fine.
Help please.
Based on:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
And:
gcc main.cpp ./cryptopp700/libcryptopp.a
Your directory structure looks like:
+- Project Folder
|
+- main.cpp
|
+- cryptopp700
|
+- cryltib.h
+- ...
+- libcryptopp.a
You should only need to add cryptopp700/
to your include header search path with -I
:
g++ main.cpp -I ./cryptopp700 ./cryptopp700/libcryptopp.a
Note that you should also use g++ (the C++ compiler), not gcc (the C compiler).
You can also install the library since it has been built. By default it installs into /usr/local
with:
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
You can install into an alternate location using 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
Then, you would change you compile and link command to something like:
g++ main.cpp -I /usr/local/include/cryptopp -o main.exe /usr/local/lib/libcryptopp.a
After an install like shown below, I normally tell folks to run the self tests. Unfortunately, the won't work if all you did was a make -j 4
or similar.
$ 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
Here's the error you would get:
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
My thinking is things should "just work" for you. You should not need to worry about CRYPTOPP_DATA_DIR
for a common case. And you certainly should not have to RTFM to make the common case work. That tells me there's a defect in our engineering process.
We are going to fix that now: Issue 760, Make self-tests run after install by a typical user.