未解析的外部符号,但垃圾箱说没关系
unresolved external symbol, but dumpbin says it's ok
我下载了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)
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
那怎么了?为什么链接器找不到符号?
乌利希期刊指南:
链接器命令行从我的项目设置
/OUT:"C:Projectscrypto_hashDebugcrypto_hash.exe" /NOLOGO /LIBPATH:"e:libscryptoppcryptopp562cryptoppWin32DLL_OutputDebug" /MANIFEST /MANIFESTFILE:"Debugcrypto_hash.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:Projectscrypto_hashDebugcrypto_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
尝试将CRYPTOPP_IMPORTS
添加到项目定义中。
From 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
或者包含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
如果不成功…
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;
查看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;
和algparam.cpp
中的实现:
#ifndef CRYPTOPP_IMPORTS
...
NAMESPACE_BEGIN(CryptoPP)
PAssignIntToInteger g_pAssignIntToInteger = NULL;
...
因此,您可能需要更改实现以确保代码使用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;
...
这可能是一个不同的问题,因为我不习惯看到DEFAULT_CHANNEL
的问题。看看CRYPTOPP_IMPORTS
如何为您工作,然后问一个不同的问题,因为这可能是一个不同的问题。