January 29th, 2010, 02:51 AM
#1
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
January 29th, 2010, 03:56 AM
#2
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] =
{
};
January 29th, 2010, 11:01 AM
#3
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.
January 29th, 2010, 11:09 AM
#4
Re: need a little help with linking error for CRC
Did you try what he said?
January 29th, 2010, 11:42 AM
#5
Re: need a little help with linking error for CRC
Yes I did with and without the #pragma once and still have a problem
January 29th, 2010, 12:11 PM
#6
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).
January 29th, 2010, 12:20 PM
#7
Re: need a little help with linking error for CRC
Thanks that helped. How do know if the CRC generated is correct?
February 2nd, 2010, 12:47 AM
#8
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() */
February 2nd, 2010, 09:33 AM
#9
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().
February 2nd, 2010, 09:36 AM
#10
Re: need a little help with linking error for CRC
Originally Posted by
liftthis
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
Forum Rules
Click Here to Expand Forum to Full Width