简体   繁体   English

使用 Qt 程序构建 crypto++ 时出现链接器错误

[英]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.我将所有crypto++的头文件和源文件(.h,.cpp)添加到我的Qt5项目中。
I built it,and it give me ten link errors.我构建了它,它给了我十个链接错误。

BackGround背景

I'm using Qt5.9.7 version.我正在使用 Qt5.9.7 版本。
The compiler is msvc2017-64bit.编译器是msvc2017-64bit。
The crypto++ is the newest 8.0.0 version. crypto++ 是最新的 8.0.0 版本。

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 .这些函数位于 MASM 源文件中,例如x64dll.asmx64masm.asmrdrand.asm You should add the source files or use -DCRYPTOPP_DISABLE_ASM .您应该添加源文件或使用-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.添加丢失的源文件后,我怀疑您会遇到更多麻烦,因为您可能没有添加存在于 Crypto++ Visual Studio 解决方案和项目文件中的预处理器宏。 You can get them from cryptlib.vcxproj (and vcxproj friends).您可以让他们cryptlib.vcxproj (和vcxproj朋友)。 Look for the PreprocessorDefinitions tag.查找PreprocessorDefinitions标签。

You should probably step back a bit.你可能应该退后一点。 Build the library using Visual Studio solution and project files.使用 Visual Studio 解决方案和项目文件构建库。 You only need to build cryptlib project, debug and release configurations.您只需要构建cryptlib项目、调试和发布配置。 Then, add the Crypto++ library as a linker option to your Qt project.然后,将 Crypto++ 库作为链接器选项添加到 Qt 项目中。

Also see Visual Studio on the Crypto++ wiki.另请参阅 Crypto++ wiki 上的Visual Studio Pay particular attention to the section Runtime Linking .请特别注意运行时链接部分。 Because you are using Qt, you will need to switch to Dynamic Runtime Linking.因为您使用的是 Qt,所以您需要切换到动态运行时链接。 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.与使用 Qt 和您的程序构建 Crypto++ 相关,您应该了解 Visual Studio 解决方案中有多个项目。 When you said you "added all header and source files" , you added both the library ( cryptlib.vcxproj ) and the test suite ( cryptest.vcxproj ).当您说您“添加了所有头文件和源文件”时,您同时添加了库 ( cryptlib.vcxproj ) 和测试套件 ( 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:您的 Qt 程序提供了一个main函数,而 Crypto++ 测试套件提供了一个main ,这就是您遇到的原因:

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 .您可以通过跳转到 Linux 然后make sources来获取头文件和源文件的列表。 You are interested in Library sources and Library headers .您对Library sourcesLibrary 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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