在visual c ++项目中获取链接错误

时间:2012-12-19 11:22:29

标签: c++ visual-c++ dll msvcr90.dll .lib

我的工作空间中有一个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代码中的方法。

`

2 个答案:

答案 0 :(得分:2)

听起来你正在混合使用不同的C运行时选项编译的对象。 IDT_DUKPT.lib是一个静态库(对象文件的集合而不是单独DLL的导入库)吗?如果是,我猜一个是使用/MTd编译的,而另一个是使用/MD选项。

有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx

有几种方法可以解决这个问题。最简单的可能是更改应用程序的编译器标志,以使用它尚未使用的/MDd/MTd中的任何一个:

  1. 右键单击解决方案资源管理器中的相关csproj,然后选择“属性”
  2. 在出现的对话框中,展开C / C ++,然后选择命令行
  3. 在对话框右侧的选项框中,添加/MTd/MDd
  4. 为完整起见,请将配置更改为Release并将/MT/MD添加到其编译器选项

答案 1 :(得分:0)

您是否尝试过创建新的DLL,然后在每次添加后添加层次结构中的每个文件,编译?

请记住,当您添加DLL时,导出就会出现。你不能直接添加这样的东西。