开发者

Showing undefined reference to a defined object

I'm trying to Hash few strings in my project. And i'm using following project that uses HAMC SHA1 algorithm http://www.codeproject.com/KB/recipes/HMACSHA1class.aspx

I was able to compile the whole code after lots of trouble. But in the end i'm left wit开发者_运维问答h the final issue relating to undefined references.

I have written following code to envoke the HMAC SHA1 classes given in the project which is as follows

BYTE Key[20] ;
BYTE digest[20] ; 

unsigned char *test = (unsigned char *)"Hi There" ; 

extern "C" {
 jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz );
}


jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
{

memset(Key, 0x0b, 20) ;

CHMAC_SHA1 HMAC_SHA1 ;

HMAC_SHA1.HMAC_SHA1(test, strlen((const char *)test), Key, sizeof(Key), digest) ;

    return env->NewStringUTF("Hello from JNI Sample!");

}

Error encountered on the following lines of HMAC_SHA1.cpp which are as follows:

CSHA1::Update((UNIT_8 *)key, key_len);

CSHA1::Update((UNIT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);

CSHA1::Update((UNIT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);

Here I get an error:

Error: undefined reference to 'CSHA1::Update(unsigned char*, unsigned long)'

Now in SHA1.h

i can see following code

///////////////////////////////////////////////////////////////////////////// // Define 8- and 32-bit variables

#ifndef UINT_32

#ifdef _MSC_VER

#define UINT_8  unsigned __int8
#define UINT_32 unsigned __int32

#else

#define UINT_8 unsigned char

#if (ULONG_MAX == 0xFFFFFFFF)
#define UINT_32 unsigned long
#else
#define UINT_32 unsigned int
#endif

#endif
#endif

//////////////////////////////////// and the function declaration is as follows:

// Update the hash value
void Update(UINT_8 *data, UINT_32 len);

I'm using windows environment but compiling in cygwin.

I'm not sure why i am getting such error

Error: undefined reference to 'CSHA1::Update(unsigned char*, unsigned long)'

Can anyone please point out what is the issue and how it can be rectified?

I believe someting is wrong with _MSC_VER cause it should be false and then UINT_8 should be defined by unsigned char. Please help.


SHA1.h does not include climits, hence ULONG_MAX is undefined. That leads to problems on 32 bit systems.

Say #include <climits> somewhere at the top of the file and you should be done.


One thing you can do is use the types defined in SHA1.h in your own code when declaring test to ensure you're calling the function with the right argument types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜