未解决的外部符号,但dumpbin说没关系

fog*_*bit 3 c++ unresolved-external crypto++

我下载了Crypto++5.62并使用默认项目设置构建它.在我的项目中,我设置了路径,cryptopp.lib并在"附加依赖项"中定义了它的名称.Crypto ++和我的项目 - VS 2008.

在构建我的项目期间,我得到:

main.obj : error LNK2001: unresolved external symbol 
  "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)

main.obj : error LNK2001: unresolved external symbol 
  "bool (__cdecl* CryptoPP::g_pAssignIntToInteger)(class type_info const &,void *,void const *)" (?g_pAssignIntToInteger@CryptoPP@@3P6A_NABVtype_info@@PAXPBX@ZA)
Run Code Online (Sandbox Code Playgroud)

dumpbin /all cryptopp.lib 在公共符号部分显示我

19471C _imp_?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B

1D6F30 __imp_?g_pAssignIntToInteger@CryptoPP@@3P6A_NABVtype_info@@PAXPBX@ZA
Run Code Online (Sandbox Code Playgroud)

那怎么了?为什么链接器找不到符号?

UPD:

我的项目设置中的链接器命令行

/OUT:"C:\Projects\crypto_hash\Debug\crypto_hash.exe" /NOLOGO /LIBPATH:"e:\libs\cryptopp\cryptopp562\cryptopp\Win32\DLL_Output\Debug" /MANIFEST /MANIFESTFILE:"Debug\crypto_hash.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Projects\crypto_hash\Debug\crypto_hash.pdb" /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT cryptopp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

jww*_*jww 5

尝试添加CRYPTOPP_IMPORTS到您的项目定义.

来自config.h:

#ifdef CRYPTOPP_EXPORTS
# define CRYPTOPP_IS_DLL
# define CRYPTOPP_DLL __declspec(dllexport)
#elif defined(CRYPTOPP_IMPORTS)
# define CRYPTOPP_IS_DLL
# define CRYPTOPP_DLL __declspec(dllimport)
#else
# define CRYPTOPP_DLL
#endif
Run Code Online (Sandbox Code Playgroud)

或者包括Crypto ++ dll.h.它设定CRYPTOPP_IMPORTS:

#if !defined(CRYPTOPP_IMPORTS) && !defined(CRYPTOPP_EXPORTS) && !defined(CRYPTOPP_DEFAULT_NO_DLL)
# ifdef CRYPTOPP_CONFIG_H
#  error To use the DLL version of Crypto++, this file must be included before any other Crypto++ header files.
# endif
# define CRYPTOPP_IMPORTS
#endif
Run Code Online (Sandbox Code Playgroud)

如果这不起作用......

g_pAssignIntToInteger来自algparams.cpp:

$ grep -R g_pAssignIntToInteger *
algparam.cpp:PAssignIntToInteger g_pAssignIntToInteger = NULL;
algparam.h:CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger;
algparam.h:     if (!(g_pAssignIntToInteger != NULL && typeid(T) == typeid(int) && g_pAssignIntToInteger(valueType, pValue, &m_value)))
integer.cpp:    if (!g_pAssignIntToInteger)
integer.cpp:        g_pAssignIntToInteger = AssignIntToInteger;
Run Code Online (Sandbox Code Playgroud)

看看声明algparam.h:

// to allow the linker to discard Integer code if not needed.
typedef bool (CRYPTOPP_API * PAssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt);
CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger;
Run Code Online (Sandbox Code Playgroud)

并执行algparam.cpp:

#ifndef CRYPTOPP_IMPORTS
...

NAMESPACE_BEGIN(CryptoPP)    
PAssignIntToInteger g_pAssignIntToInteger = NULL;
...
Run Code Online (Sandbox Code Playgroud)

因此,您可能需要更改实现以确保代码使用g_pAssignIntToInteger(以防止被丢弃).不幸的是,目前没有任何想法.


DEFAULT_CHANNEL声明cryptlib.h并在cryptolib.cpp以下位置分配存储空间:

$ grep -R DEFAULT_CHANNEL *
...
cryptlib.cpp:const std::string DEFAULT_CHANNEL;
...
cryptlib.h:extern CRYPTOPP_DLL const std::string DEFAULT_CHANNEL;
...
Run Code Online (Sandbox Code Playgroud)

这可能是一个不同的问题,因为我不习惯看到问题DEFAULT_CHANNEL.看看它是如何CRYPTOPP_IMPORTS为您工作,然后问一个不同的问题,因为这可能是一个不同的问题.

  • #include &lt;dll.h&gt; 在所有其他加密包含之前也为我解决了这个问题。 (3认同)