Need help compiling crypto++

Hello I am trying to compile test.cpp which is built-in test file in crypto++ library. I have made makefile but it does not work.

"D:/Dropbox/cpp/praks/praks8" is in my case directory where all the crypto++ cpp and h files are.

my makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#####################################################
# You may need to change the parameters under here. #
#####################################################

# Step 1: Choose a compiler. By default, use clang++

# If you use clang++, make sure the following line does not start with a comment (#)
CXX=g++
# If you use g++, uncomment the following line
#CXX=g++

# Set default compiler parameters
# -Wall 	shows all warnings when compiling, always use this!
# -std=c++11 	enables the C++11 standard mode
CXXFLAGS = -Wall -std=c++11

# Use the directory that *contains* the boost directory
CRYPTO_LIBRARIES = D:/Dropbox/cpp/praks/praks8


# The -g flag adds debugging support
CXXFLAGS += -fpermissive
LFLAGS += -L$(CRYPTO_LIBRARIES)

#########################
# Settings for the apps # 
#########################

testOBJS = obj/test.o
testAPP = bin/test


# This is the first target. It will be built when you run 'make' or 'make all'
all: $(testAPP)

# Rules for linking the test apps
$(testAPP): $(testOBJS)
	$(CXX) $(testOBJS) -o $(testAPP) $(LFLAGS)


# Compile each source file of the apps

obj/test.o: src/test.cpp
	$(CXX) $(CXXFLAGS) -c src/test.cpp -o obj/test.o

clean: 
	rm -rf $(testAPP) $(testOBJS)

doc: 
	doxygen



output of make command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
D:\Dropbox\cpp\praks\projekt>make
g++ obj/test.o -o bin/test -LD:/Dropbox/cpp/praks/praks8
obj/test.o: In function `main':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:136: undefined reference to `RegisterFactories()'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:205: undefined reference to `CryptoPP::MaurerRandomnessTest::MaurerRandomnessT
est()'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:207: undefined reference to `CryptoPP::DEFAULT_CHANNEL'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:208: undefined reference to `CryptoPP::MaurerRandomnessTest::GetTestValue() co
nst'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:263: undefined reference to `CryptoPP::NewIntegrityCheckingMAC()'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:265: undefined reference to `CryptoPP::DEFAULT_CHANNEL'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:265: undefined reference to `CryptoPP::DEFAULT_CHANNEL'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:265: undefined reference to `CryptoPP::HashFilter::HashFilter(CryptoPP::HashTr
ansformation&, CryptoPP::BufferedTransformation*, bool, int, std::string const&, std::string const&)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:266: undefined reference to `CryptoPP::MeterFilter::AddRangeToSkip(unsigned in
t, unsigned long long, unsigned long long, bool)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:267: undefined reference to `CryptoPP::MeterFilter::AddRangeToSkip(unsigned in
t, unsigned long long, unsigned long long, bool)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:268: undefined reference to `CryptoPP::MeterFilter::AddRangeToSkip(unsigned in
t, unsigned long long, unsigned long long, bool)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:269: undefined reference to `CryptoPP::MeterFilter::AddRangeToSkip(unsigned in
t, unsigned long long, unsigned long long, bool)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:287: undefined reference to `CryptoPP::g_nullNameValuePairs'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:287: undefined reference to `RunTestDataFile(char const*, CryptoPP::NameValueP
airs const&, bool)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:343: undefined reference to `BenchmarkAll(double, double)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:345: undefined reference to `BenchmarkAll2(double, double)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:351: undefined reference to `FIPS140_SampleApplication()'
obj/test.o: In function `Z27FIPS140_GenerateRandomFilesv':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:405: undefined reference to `CryptoPP::DEFAULT_CHANNEL'
obj/test.o: In function `Z13StringToValueIiLb1EET_RKSs':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:433: undefined reference to `CryptoPP::Integer::Integer(char const*)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:434: undefined reference to `CryptoPP::Integer::ConvertToLong() const'
obj/test.o: In function `Z14GenerateRSAKeyjPKcS0_S0_':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:468: undefined reference to `CryptoPP::RandomPool::RandomPool()'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:469: undefined reference to `CryptoPP::RandomPool::IncorporateEntropy(unsigned
 char const*, unsigned int)'
obj/test.o: In function `Z16RSAEncryptStringPKcS0_S0_':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:487: undefined reference to `CryptoPP::RandomPool::RandomPool()'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:488: undefined reference to `CryptoPP::RandomPool::IncorporateEntropy(unsigned
 char const*, unsigned int)'
D:\Dropbox\cpp\praks\projekt/src/test.cpp:491: undefined reference to `CryptoPP::StringSinkTemplate<std::string>::String
SinkTemplate(std::string&)'
obj/test.o: In function `Z16RSADecryptStringPKcS0_':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:501: undefined reference to `CryptoPP::StringSinkTemplate<std::string>::String
SinkTemplate(std::string&)'
obj/test.o: In function `Z13RSAVerifyFilePKcS0_S0_':
D:\Dropbox\cpp\praks\projekt/src/test.cpp:523: undefined reference to `CryptoPP::SignatureVerificationFilter::SignatureV
erificationFilter(CryptoPP::PK_Verifier const&, CryptoPP::BufferedTransformation*, unsigned int)'
obj/test.o: In function `Z10DigestFilePKc':
D:\Dropbox\cpp\praks\projekt/srmake: *** [bin/test] Error 3 
It looks like you forgot to actually link to the static library. You only added the search directory with -L. I expect it should be -lcryptopp or something.
Now my makefile looks like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#####################################################
# You may need to change the parameters under here. #
#####################################################

# Step 1: Choose a compiler. By default, use clang++

# If you use clang++, make sure the following line does not start with a comment (#)
CXX=g++
# If you use g++, uncomment the following line
#CXX=g++

# Set default compiler parameters
# -Wall 	shows all warnings when compiling, always use this!
# -std=c++11 	enables the C++11 standard mode
CXXFLAGS = -Wall -std=c++11

# Use the directory that *contains* the boost directory
CRYPTO_LIBRARIES = /home/rain/cppproject


# The -g flag adds debugging support
CXXFLAGS += -I$(CRYPTO_LIBRARIES) -fpermissive 
LFLAGS += -L$(CRYPTO_LIBRARIES) -lcryptopp

#########################
# Settings for the apps # 
#########################

testOBJS = obj/test.o
testAPP = bin/test


# This is the first target. It will be built when you run 'make' or 'make all'
all: $(testAPP)

# Rules for linking the test apps
$(testAPP): $(testOBJS)
	$(CXX) $(testOBJS) -o $(testAPP) $(LFLAGS)


# Compile each source file of the apps

obj/test.o: src/test.cpp
	$(CXX) $(CXXFLAGS) -c src/test.cpp -o obj/test.o

clean: 
	rm -rf $(testAPP) $(testOBJS)

doc: 
	doxygen



And now it tells me:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
rain@hp:~/cpp$ make
g++ obj/test.o -o bin/test -L/home/rain/cppproject -lcryptopp
obj/test.o: In function `main':
test.cpp:(.text+0x2b8): undefined reference to `RegisterFactories()'
test.cpp:(.text+0x10af): undefined reference to `RunTestDataFile(char const*, CryptoPP::NameValuePairs const&, bool)'
test.cpp:(.text+0x1948): undefined reference to `BenchmarkAll(double, double)'
test.cpp:(.text+0x1ade): undefined reference to `BenchmarkAll2(double, double)'
test.cpp:(.text+0x1bf3): undefined reference to `FIPS140_SampleApplication()'
obj/test.o: In function `Validate(int, bool, char const*)':
test.cpp:(.text+0x7669): undefined reference to `ValidateAll(bool)'
test.cpp:(.text+0x7676): undefined reference to `TestSettings()'
test.cpp:(.text+0x7683): undefined reference to `TestOS_RNG()'
test.cpp:(.text+0x7690): undefined reference to `ValidateMD5()'
test.cpp:(.text+0x769d): undefined reference to `ValidateSHA()'
test.cpp:(.text+0x76aa): undefined reference to `ValidateDES()'
test.cpp:(.text+0x76b7): undefined reference to `ValidateIDEA()'
test.cpp:(.text+0x76c4): undefined reference to `ValidateARC4()'
test.cpp:(.text+0x76d1): undefined reference to `ValidateRC5()'
test.cpp:(.text+0x76de): undefined reference to `ValidateBlowfish()'
test.cpp:(.text+0x76eb): undefined reference to `ValidateThreeWay()'
test.cpp:(.text+0x76f8): undefined reference to `ValidateBBS()'
test.cpp:(.text+0x7705): undefined reference to `ValidateDH()'
test.cpp:(.text+0x7712): undefined reference to `ValidateRSA()'
test.cpp:(.text+0x771f): undefined reference to `ValidateElGamal()'
test.cpp:(.text+0x7732): undefined reference to `ValidateDSA(bool)'
test.cpp:(.text+0x773f): undefined reference to `ValidateSAFER()'
test.cpp:(.text+0x774c): undefined reference to `ValidateLUC()'
test.cpp:(.text+0x7759): undefined reference to `ValidateRabin()'
test.cpp:(.text+0x7766): undefined reference to `ValidateECP()'
test.cpp:(.text+0x7773): undefined reference to `ValidateEC2N()'
test.cpp:(.text+0x7780): undefined reference to `ValidateGOST()'
test.cpp:(.text+0x778d): undefined reference to `ValidateTiger()'
test.cpp:(.text+0x779a): undefined reference to `ValidateRIPEMD()'
test.cpp:(.text+0x77a7): undefined reference to `ValidateHMAC()'
test.cpp:(.text+0x77b4): undefined reference to `ValidateSHARK()'
test.cpp:(.text+0x77c1): undefined reference to `ValidateLUC_DH()'
test.cpp:(.text+0x77ce): undefined reference to `ValidateLUC_DL()'
test.cpp:(.text+0x77db): undefined reference to `ValidateSEAL()'
test.cpp:(.text+0x77e8): undefined reference to `ValidateCAST()'
test.cpp:(.text+0x77f5): undefined reference to `ValidateSquare()'
test.cpp:(.text+0x7802): undefined reference to `ValidateRC2()'
test.cpp:(.text+0x780f): undefined reference to `ValidateRC6()'
test.cpp:(.text+0x781c): undefined reference to `ValidateMARS()'
test.cpp:(.text+0x7829): undefined reference to `ValidateRW()'
test.cpp:(.text+0x7836): undefined reference to `ValidateMD2()'
test.cpp:(.text+0x7843): undefined reference to `ValidateNR()'
test.cpp:(.text+0x7850): undefined reference to `ValidateMQV()'
test.cpp:(.text+0x785d): undefined reference to `ValidateRijndael()'
test.cpp:(.text+0x786a): undefined reference to `ValidateTwofish()'
test.cpp:(.text+0x7877): undefined reference to `ValidateSerpent()'
test.cpp:(.text+0x7884): undefined reference to `ValidateCipherModes()'
test.cpp:(.text+0x7891): undefined reference to `ValidateCRC32()'
test.cpp:(.text+0x789e): undefined reference to `ValidateECDSA()'
test.cpp:(.text+0x78ab): undefined reference to `ValidateXTR_DH()'
test.cpp:(.text+0x78b8): undefined reference to `ValidateSKIPJACK()'
test.cpp:(.text+0x78c5): undefined reference to `ValidateSHA2()'
test.cpp:(.text+0x78d2): undefined reference to `ValidatePanama()'
test.cpp:(.text+0x78df): undefined reference to `ValidateAdler32()'
test.cpp:(.text+0x78ec): undefined reference to `ValidateMD4()'
test.cpp:(.text+0x78f9): undefined reference to `ValidatePBKDF()'
test.cpp:(.text+0x7906): undefined reference to `ValidateESIGN()'
test.cpp:(.text+0x7913): undefined reference to `ValidateDLIES()'
test.cpp:(.text+0x791d): undefined reference to `ValidateBaseCode()'
test.cpp:(.text+0x7927): undefined reference to `ValidateSHACAL2()'
test.cpp:(.text+0x7931): undefined reference to `ValidateCamellia()'
test.cpp:(.text+0x793b): undefined reference to `ValidateWhirlpool()'
test.cpp:(.text+0x7945): undefined reference to `ValidateTTMAC()'
test.cpp:(.text+0x794f): undefined reference to `ValidateSalsa()'
test.cpp:(.text+0x7959): undefined reference to `ValidateSosemanuk()'
test.cpp:(.text+0x7963): undefined reference to `ValidateVMAC()'
test.cpp:(.text+0x796d): undefined reference to `ValidateCCM()'
test.cpp:(.text+0x7977): undefined reference to `ValidateGCM()'
test.cpp:(.text+0x7981): undefined reference to `ValidateCMAC()'
test.cpp:(.text+0x798b): undefined reference to `ValidateHKDF()'
collect2: error: ld returned 1 exit status
Makefile:38: recipe for target 'bin/test' failed
make: *** [bin/test] Error 1
rain@hp:~/cpp$ 

Last edited on
"D:/Dropbox/cpp/praks/praks8" is in my case directory where all the crypto++ cpp and h files are.


And does it also contain the library file, probably named libcryptopp.so or libcryptopp.a ?
Some things about your make file not related to your problem.

1
2
# If you use clang++, make sure the following line does not start with a comment (#)
CXX=g++


Should that be:

CXX = clang++

to use clang ?

1
2
3
4
5
6
7
8
9
# Set default compiler parameters
# -std=c++11 	enables the C++11 standard mode
# -Wall 	shows all warnings when compiling, always use this!
# -Wextra extra warnings not enabled by -Wall
# -pedantic-errors  even more warnings, these will be made into errors
# always at least use these 3 warning options, warnings are your friend :+)
# there are even more warnings not enabled by all this, look at the gcc manual

CXXFLAGS +=  -std=c++11 -Wall -Wextra -pedantic-errors
Topic archived. No new replies allowed.