我的工作空间中有一个visual c++
项目完全依赖于.lib
(静态库)。现在我想使用visual c ++中的现有代码创建一个dll
项目,但它向我显示linking
错误:
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: "public: virtual __thiscall exception::~exception(void)" (??1exception@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: "public: __thiscall exception::exception(char const * const &)" (??0exception@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgheap.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgheap.obj)
LINK : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/finaliTest.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
我是这个visual C++
的新手。我应该如何处理?
DllMain
的代码:
#include "stdafx.h"
#include "IDT_DUKPT.h"
unsigned char stringKSN[10];
unsigned char m_nderivation_key[16];
unsigned char m_ninitial_key[16];
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void OnDecryption(){
GetKey(stringKSN, m_nderivation_key, m_ninitial_key);
// Initialization of the method are written in `.lib` file.
}
IDT_DUKPT.H
的位置是:
//IDT_DUKPT.h
#define _IDT_DUKPT_H_
// TDES Encryption
void TDES_Encryption(BYTE *Data, BYTE *Key, BYTE *InitalVector, int Length);
// TDES Decryption
void TDES(BYTE *Data, BYTE *Key, BYTE *InitalVector, int Length);
// Get the Initial Key
void GetKey(BYTE *KSN, BYTE *BDK, BYTE *InitialKey);
我还将IDT_DUKPT.lib
放在项目文件夹中,并将.lib
链接添加到项目设置中。
我的主要目标是创建dll
,以便我可以使用java
代码中的JNA
代码中的方法。
`
答案 0 :(得分:2)
听起来你正在混合使用不同的C运行时选项编译的对象。 IDT_DUKPT.lib
是一个静态库(对象文件的集合而不是单独DLL的导入库)吗?如果是,我猜一个是使用/MTd
编译的,而另一个是使用/MD
选项。
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx。
有几种方法可以解决这个问题。最简单的可能是更改应用程序的编译器标志,以使用它尚未使用的/MDd
或/MTd
中的任何一个:
/MTd
或/MDd
/MT
或/MD
添加到其编译器选项答案 1 :(得分:0)
您是否尝试过创建新的DLL,然后在每次添加后添加层次结构中的每个文件,编译?
请记住,当您添加DLL时,导出就会出现。你不能直接添加这样的东西。