简体   繁体   中英

Linker error while building crypto++ with Qt program

Problem

I add all the crypto++'s header file and source file(.h,.cpp) to my Qt5 project.
I built it,and it give me ten link errors.

BackGround

I'm using Qt5.9.7 version.
The compiler is msvc2017-64bit.
The crypto++ is the newest 8.0.0 version.

Errors

test.obj:-1: error: LNK2005: main already defined in main.obj
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)

These functions are in the MASM source files, like x64dll.asm , x64masm.asm and rdrand.asm . You should add the source files or use -DCRYPTOPP_DISABLE_ASM .

Once you add the missing source files I suspect you will have more troubles because you probably did not add preprocessor macros present in the Crypto++ Visual Studio solution and project files. You can get them from cryptlib.vcxproj (and vcxproj friends). Look for the PreprocessorDefinitions tag.

You should probably step back a bit. Build the library using Visual Studio solution and project files. You only need to build cryptlib project, debug and release configurations. Then, add the Crypto++ library as a linker option to your Qt project.

Also see Visual Studio on the Crypto++ wiki. Pay particular attention to the section Runtime Linking . Because you are using Qt, you will need to switch to Dynamic Runtime Linking. The wiki page tells you how to do it.


Related to building Crypto++ with Qt and your program, you should understand there are multiple projects in the Visual Studio solution. When you said you "added all header and source files" , you added both the library ( cryptlib.vcxproj ) and the test suite ( cryptest.vcxproj ). You only need the library files, and not the test files.

Your Qt program supplied a main functions and the Crypto++ test suite provided a main , and that is why you are experiencing:

test.obj:-1: error: LNK2005: main already defined in main.obj

You can get a list of the header and source files by jumping over to Linux and then make sources . You are interested in Library sources and Library headers .

$ make sources
***** Library sources *****
cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp a
rc4.cpp aria.cpp aria_simd.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64
.cpp basecode.cpp bfinit.cpp blake2.cpp blake2b_simd.cpp blake2s_simd.cpp blowfi
sh.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cp
p chacha_avx.cpp chacha_simd.cpp cham.cpp cham_simd.cpp channels.cpp cmac.cpp cr
c.cpp crc_simd.cpp darn.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp
 donna_32.cpp donna_64.cpp donna_sse.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp e
cp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips14
0.cpp fipstest.cpp gcm.cpp gcm_simd.cpp gf256.cpp gf2_32.cpp gf2n.cpp gf2n_simd.
cpp gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cp
p hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp
keccakc.cpp lea.cpp lea_simd.cpp lsh.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.
cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon_simd.cpp oae
p.cpp ospstore.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp po
lynomi.cpp ppc_power7.cpp ppc_power8.cpp ppc_power9.cpp ppc_simd.cpp pssr.cpp pu
bkey.cpp queue.cpp rabbit.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdr
and.cpp rdtables.cpp rijndael.cpp rijndael_simd.cpp ripemd.cpp rng.cpp rsa.cpp r
w.cpp safer.cpp salsa.cpp scrypt.cpp seal.cpp seed.cpp serpent.cpp sha.cpp sha3.
cpp sha_simd.cpp shacal2.cpp shacal2_simd.cpp shark.cpp sharkbox.cpp simeck.cpp
simeck_simd.cpp simon.cpp simon128_simd.cpp simon64_simd.cpp skipjack.cpp sm3.cp
p sm4.cpp sm4_simd.cpp sosemanuk.cpp speck.cpp speck128_simd.cpp speck64_simd.cp
p square.cpp squaretb.cpp sse_simd.cpp strciphr.cpp tea.cpp tftables.cpp threefi
sh.cpp tiger.cpp tigertab.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wake.
cpp whrlpool.cpp xed25519.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zli
b.cpp

***** Library headers *****
3way.h adler32.h adv_simd.h aes.h aes_armv4.h algebra.h algparam.h androidpay.h
arc4.h argnames.h aria.h arm_simd.h asn.h authenc.h base32.h base64.h basecode.h
 blake2.h blowfish.h blumshub.h camellia.h cast.h cbcmac.h ccm.h chacha.h cham.h
 channels.h cmac.h config.h cpu.h crc.h cryptlib.h darn.h default.h des.h dh.h d
h2.h dll.h dmac.h donna.h donna_32.h donna_64.h donna_sse.h drbg.h dsa.h eax.h e
c2n.h eccrypto.h ecp.h ecpoint.h elgamal.h emsa2.h eprecomp.h equihash.h esign.h
 fhmqv.h files.h filters.h fips140.h fltrimpl.h gcm.h gf256.h gf2_32.h gf2n.h gf
pcrypt.h gost.h gzip.h hashfwd.h hc128.h hc256.h hex.h hight.h hkdf.h hmac.h hmq
v.h hrtimer.h ida.h idea.h integer.h iterhash.h kalyna.h keccak.h keccakc.h lea.
h lsh.h lubyrack.h luc.h mars.h md2.h md4.h md5.h mdc.h mersenne.h misc.h modari
th.h modes.h modexppc.h mqueue.h mqv.h naclite.h nbtheory.h nr.h oaep.h oids.h o
spstore.h osrng.h ossig.h padlkrng.h panama.h pch.h pem.h pkcspad.h poly1305.h p
olynomi.h ppc_simd.h pssr.h pubkey.h pwdbased.h queue.h rabbit.h rabin.h randpoo
l.h rc2.h rc5.h rc6.h rdrand.h rijndael.h ripemd.h rng.h rsa.h rw.h safer.h sals
a.h scrypt.h seal.h secblock.h seckey.h seed.h serpent.h serpentp.h sha.h sha3.h
 shacal2.h shark.h simeck.h simon.h simple.h siphash.h skipjack.h sm3.h sm4.h sm
artptr.h sosemanuk.h speck.h square.h stdcpp.h strciphr.h tea.h threefish.h tige
r.h trap.h trunhash.h ttmac.h tweetnacl.h twofish.h vmac.h wake.h whrlpool.h wor
ds.h xed25519.h xtr.h xtrcrypt.h zdeflate.h zinflate.h zlib.h

***** Test sources *****
adhoc.cpp test.cpp bench1.cpp bench2.cpp bench3.cpp datatest.cpp dlltest.cpp fip
salgt.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp valid
at5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp regtes
t1.cpp regtest2.cpp regtest3.cpp regtest4.cpp

***** Test headers *****
bench.h factory.h validate.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM