CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2006
    Posts
    32

    need a little help with linking error for CRC

    I need some help with compiler error.
    error link2005: _crcTable already defined in crc.obj


    I attach the zip file below:
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: need a little help with linking error for CRC

    You're CRC header has no guards. Use one of these two:
    Code:
    #ifndef _CRC_H_
    #define _CRC_H_
    
    // header content goes here
    
    #endif
    or (only for Microsoft compilers)
    Code:
    #pragma once 
    
    // header content goes here
    You should try defining your table as constant:
    Code:
    const unsigned long  crcTable[256] =
    {
    };
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Nov 2006
    Posts
    32

    Re: need a little help with linking error for CRC

    Still need to address the error link2005: _crcTable already defined in crc.obj,

    I can't see it.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: need a little help with linking error for CRC

    Did you try what he said?

  5. #5
    Join Date
    Nov 2006
    Posts
    32

    Re: need a little help with linking error for CRC

    Yes I did with and without the #pragma once and still have a problem

  6. #6
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: need a little help with linking error for CRC

    1) in crc.h , you can just declare the variable

    Code:
    extern unsigned long  crcTable[256];
    2) in crc.c you define the variable

    Code:
    #include "crc.h"
    
    unsigned long  crcTable[256] =
    {
     0x00000000L, 0x00B20606L, 0x01640C0CL, 0x01D60A0AL,
    /* etc */
    3) You should put header guards in all .h files (not needed in your simple example).

  7. #7
    Join Date
    Nov 2006
    Posts
    32

    Re: need a little help with linking error for CRC

    Thanks that helped. How do know if the CRC generated is correct?

  8. #8
    Join Date
    Nov 2006
    Posts
    32

    Re: need a little help with linking error for CRC

    I am having trouble trying to get the CRC append to the test data, and print out the data with the appended crc.


    #include <stdio.h>
    #include <string.h>

    #include "crc.h"

    static unsigned long crcSum;

    void
    main(void)
    {
    // unsigned char test[] = "123456789";
    unsigned char test[13] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};


    /*
    * Print the check value for the selected CRC algorithm.
    */

    printf("Payload: 0x%X\n", test);
    printf("The crcFast() of \"123456789\" is 0x%X\n", crcFast(test, strlen(test)));

    crcSum = crcFast(test, strlen(test));
    // printf("Payload is 0x%X\n", test);
    // printf("CRC is 0x%X\n", crcSum);

    // Add CRC To message
    *(unsigned long *)&test[9] = (unsigned long)crcSum /*crcSum*/;

    printf("Payload with CRC Appended: 0x%X\n", *(unsigned long *)&test[9]);




    } /* main() */

  9. #9
    Join Date
    Feb 2005
    Posts
    2,160

    Re: need a little help with linking error for CRC

    "test" is not a C-string (no NULL terminator) so you get undefined behavior when you try to use calls like printf() and strlen().

  10. #10
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: need a little help with linking error for CRC

    Quote Originally Posted by liftthis View Post
    Thanks that helped. How do know if the CRC generated is correct?
    This may help
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured