I need some help with compiler error.
error link2005: _crcTable already defined in crc.obj
I attach the zip file below:
Printable View
I need some help with compiler error.
error link2005: _crcTable already defined in crc.obj
I attach the zip file below:
You're CRC header has no guards. Use one of these two:
or (only for Microsoft compilers)Code:#ifndef _CRC_H_
#define _CRC_H_
// header content goes here
#endif
You should try defining your table as constant:Code:#pragma once
// header content goes here
Code:const unsigned long crcTable[256] =
{
};
Still need to address the error link2005: _crcTable already defined in crc.obj,
I can't see it.
Did you try what he said?
Yes I did with and without the #pragma once and still have a problem
1) in crc.h , you can just declare the variable
2) in crc.c you define the variableCode:extern unsigned long crcTable[256];
3) You should put header guards in all .h files (not needed in your simple example).Code:#include "crc.h"
unsigned long crcTable[256] =
{
0x00000000L, 0x00B20606L, 0x01640C0CL, 0x01D60A0AL,
/* etc */
Thanks that helped. How do know if the CRC generated is correct?
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() */
"test" is not a C-string (no NULL terminator) so you get undefined behavior when you try to use calls like printf() and strlen().