在Visual C 项目中获取链接错误

Getting linking error in visual c++ project

本文关键字:获取 链接 错误 项目 Visual      更新时间:2023-10-16

我的工作空间中有一个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

`

听起来您是在混合了与C Run-Times不同选项编译的对象。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. 有关完整性,请更改配置以释放并将/MT/MD添加到其编译器选项

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

请记住,当您添加DLL时,导出会出现图片。您将无法直接添加。