Pergunta

I have a visual c++ project in my work space which is totally depend on .lib (static library). Now i want to create a dll project using the existing code in visual c++ but it shows me following linking error:

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.

I am newbie in this visual C++. How should i procced?

  • code for 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.
    
       }
    

Where as the IDT_DUKPT.H is:

//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);

I also put the IDT_DUKPT.lib in my project folder and add the .lib link to the project setting.

My main aim is to create a dll, So that i can use the methods from my java code using JNA.

`

Foi útil?

Solução

It sounds like you're mixing objects that were compiled with different options for C run-times. Is IDT_DUKPT.lib a static library (a collection of object files rather than an import library for a separate DLL)? If it is, I'd guess one was compiled using /MTd while the other is using the /MD option.

See http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx for details.

There are a few ways you could fix this. The easiest is probably to change the compiler flags for your app to use whichever of /MDd or /MTd it wasn't already using:

  1. Right click on the relevant csproj in Solution Explorer and select Properties
  2. In the dialog that appears, expand C/C++ then select Command Line
  3. In the options box on the right of the dialog, add /MTd or /MDd
  4. For completeness, change the configuration to Release and add /MT or /MD to its compiler options

Outras dicas

Have you tried creating the new DLL, then add each file in the hierarchy, after each addition, compile?

Remember, when you are adding a DLL, the exporting comes into picture. You will not be able directly add like that.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top