Linking Error...

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2005
Posts: 3
Reputation: JSThePatriot is an unknown quantity at this point 
Solved Threads: 0
JSThePatriot JSThePatriot is offline Offline
Newbie Poster

Linking Error...

 
0
  #1
Jun 27th, 2005
Okay I use Dev-C++ as my IDE. I have never linked my own files. I am pretty much a noob on C++, but not to programming in general.

My issue that I have been almost pulling my hair out with is this. I am using a premade MD5 header file (or rather am trying to use). I have yet to get it to work. Even using the sample I downloaded with the source files.

Here is the header file: md5.h
  1. /////////////////////////////////////////////////////////////////////////
  2. // MD5.cpp
  3. // Implementation file for MD5 class
  4. //
  5. // This C++ Class implementation of the original RSA Data Security, Inc.
  6. // MD5 Message-Digest Algorithm is copyright (c) 2002, Gary McNickle.
  7. // All rights reserved. This software is a derivative of the "RSA Data
  8. // Security, Inc. MD5 Message-Digest Algorithm"
  9. //
  10. // You may use this software free of any charge, but without any
  11. // warranty or implied warranty, provided that you follow the terms
  12. // of the original RSA copyright, listed below.
  13. //
  14. // Original RSA Data Security, Inc. Copyright notice
  15. /////////////////////////////////////////////////////////////////////////
  16. //
  17. // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  18. // rights reserved.
  19. //
  20. // License to copy and use this software is granted provided that it
  21. // is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  22. // Algorithm" in all material mentioning or referencing this software
  23. // or this function.
  24. // License is also granted to make and use derivative works provided
  25. // that such works are identified as "derived from the RSA Data
  26. // Security, Inc. MD5 Message-Digest Algorithm" in all material
  27. // mentioning or referencing the derived work.
  28. // RSA Data Security, Inc. makes no representations concerning either
  29. // the merchantability of this software or the suitability of this
  30. // software for any particular purpose. It is provided "as is"
  31. // without express or implied warranty of any kind.
  32. // These notices must be retained in any copies of any part of this
  33. // documentation and/or software.
  34. /////////////////////////////////////////////////////////////////////////
  35.  
  36. typedef unsigned int uint4;
  37. typedef unsigned short int uint2;
  38. typedef unsigned char uchar;
  39.  
  40. char* PrintMD5(uchar md5Digest[16]);
  41. char* MD5String(char* szString);
  42. char* MD5File(char* szFilename);
  43.  
  44. class md5
  45. {
  46. // Methods
  47. public:
  48. md5() { Init(); }
  49. void Init();
  50. void Update(uchar* chInput, uint4 nInputLen);
  51. void Finalize();
  52. uchar* Digest() { return m_Digest; }
  53.  
  54. private:
  55.  
  56. void Transform(uchar* block);
  57. void Encode(uchar* dest, uint4* src, uint4 nLength);
  58. void Decode(uint4* dest, uchar* src, uint4 nLength);
  59.  
  60.  
  61. inline uint4 rotate_left(uint4 x, uint4 n)
  62. { return ((x << n) | (x >> (32-n))); }
  63.  
  64. inline uint4 F(uint4 x, uint4 y, uint4 z)
  65. { return ((x & y) | (~x & z)); }
  66.  
  67. inline uint4 G(uint4 x, uint4 y, uint4 z)
  68. { return ((x & z) | (y & ~z)); }
  69.  
  70. inline uint4 H(uint4 x, uint4 y, uint4 z)
  71. { return (x ^ y ^ z); }
  72.  
  73. inline uint4 I(uint4 x, uint4 y, uint4 z)
  74. { return (y ^ (x | ~z)); }
  75.  
  76. inline void FF(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
  77. { a += F(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
  78.  
  79. inline void GG(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
  80. { a += G(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
  81.  
  82. inline void HH(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
  83. { a += H(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
  84.  
  85. inline void II(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
  86. { a += I(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
  87.  
  88. // Data
  89. private:
  90. uint4 m_State[4];
  91. uint4 m_Count[2];
  92. uchar m_Buffer[64];
  93. uchar m_Digest[16];
  94. uchar m_Finalized;
  95.  
  96. };

Then we have their test file they are trying to call the functions with: md5test.cpp
  1.  
  2. // md5Test
  3. // A simple test of the MD5 library.
  4.  
  5.  
  6. #include <stdio.h>
  7. #include "md5.h"
  8.  
  9.  
  10. int main(void)
  11. {
  12. printf("MD5 Key of the phrase 'md5Test' = <%s>\n", MD5String("md5Test"));
  13.  
  14. printf("MD5 Key of the file 'md5.cpp' = <%s>\n", MD5File("md5.cpp"));
  15.  
  16. return 0;
  17. }

And now the error given is...
[Linker error] undefined reference to `MD5String(char*)'
I have even gone as far as to include all the header source in the file and remove the include, but that didnt even work .

Thank you for anyone willing to read this long arsed post and help me.
JS
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 36
Reputation: Raven11 is an unknown quantity at this point 
Solved Threads: 1
Raven11 Raven11 is offline Offline
Light Poster

Re: Linking Error...

 
0
  #2
Jun 27th, 2005
lol, a possible problem is because of the compiler you are using is not updated with the .lib files necessary for this project.

Try commenting out the line:
printf("MD5 Key of the phrase 'md5Test' = <%s>\n", MD5String("md5Test"));
This should get it to compile, however you will not be able to use the MD5Test.

Something else that might work for you (However this will limit some experience.. possibly) is this:

  1. char * MyVar = "AStringWee";
  2. printf(MD5String(MyVar));

I am not fully experienced with <stdio.h> so printf might not be what you want to use for the above example.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 13
Reputation: oboler is an unknown quantity at this point 
Solved Threads: 1
oboler's Avatar
oboler oboler is offline Offline
Newbie Poster

Re: Linking Error...

 
0
  #3
Jun 27th, 2005
You may need to include the line:

using namespace std;

In the .h file after the includes statements. Can't remember the reason for it other than a change to the language a few years back. At any rate you have a scope problem and that might just fix it. - I am guessing though. I did something similar a few years back and we we had code that worked, and a year later didn't. Rather painful to work out why.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 3
Reputation: JSThePatriot is an unknown quantity at this point 
Solved Threads: 0
JSThePatriot JSThePatriot is offline Offline
Newbie Poster

Re: Linking Error...

 
0
  #4
Jun 27th, 2005
I appreciate both of your responses. Below is the code I came up with to test it... it actually tries a bit of what you both said.

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <md5.h>
  5.  
  6. using namespace std;
  7.  
  8. char* szString = "Some string you want to generate an MD5 key for.";
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. char* sString = MD5String(szString);
  13.  
  14. cout << "Some string you want to generate an MD5 key for." << "MD5 Output: " << sString;
  15.  
  16. system("PAUSE");
  17. return EXIT_SUCCESS;
  18. }

If you can come up with anything else please let me know. (On the first post example I actually didnt copy both errors. It has a problem with any function from that header file .

JS
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 3
Reputation: JSThePatriot is an unknown quantity at this point 
Solved Threads: 0
JSThePatriot JSThePatriot is offline Offline
Newbie Poster

Re: Linking Error...

 
0
  #5
Jun 27th, 2005
Okay... for some reason I had forgotten to add the files to the project, but I also thought I didnt have to since I "#included """ them :-|

Oh well I appreciate the help you offered.

JS
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 13
Reputation: oboler is an unknown quantity at this point 
Solved Threads: 1
oboler's Avatar
oboler oboler is offline Offline
Newbie Poster

Re: Linking Error...

 
0
  #6
Jun 28th, 2005
Glad to hear you got it sorted. I was just thinking that it sounds like the linker can't see the file... i.e. wrong directory.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC