Click here to Skip to main content
15,897,187 members

Please tell the LNK2019 error solution

Tarun Batra asked:

Open original thread
I am getting an error that is

C++
Socket.obj : error LNK2019: unresolved external symbol "int __cdecl calc_check(int)" (?calc_check@@YAHH@Z) referenced in function _main


This is mine socket.cpp
C++
int main()
{
int hh=2;

    //int chkvalue=calculatechecksum();
    int chkvalue=calc_check(hh);
}

This is mine checksum.c
C++
//===================================================== file = checksum.c =====

//----- Include files ---------------------------------------------------------
#include <stdio.h>                  // Needed for printf()
#include <stdlib.h>                 // Needed for rand()
#include <windows.h>
#include<conio.h>
#include <stdint.h>
#include"Constant.h"

//----- Type defines ----------------------------------------------------------
typedef unsigned char      byte;    // Byte is a char
typedef unsigned short int word16;  // 16-bit word is a short int
typedef unsigned int       word32;  // 32-bit word is an int

//----- Defines ---------------------------------------------------------------
#define BUFFER_LEN        6      // Length of buffer
//extern char data[6];
//char data[6]="CM00";
 extern char data[6]="CM00";
   word16      check;  
//----- Prototypes ------------------------------------------------------------
word16 checksum(char *addr, word32 count);
//int calc_check(int);
//===== Main program ==========================================================
int calc_check(int w)
{
 //byte        buff[BUFFER_LEN]; // Buffer of packet bytes

          // 16-bit checksum value
  word32      i;                // Loop counter

  // Load buffer with BUFFER_LEN random bytes
  for (i=0; i<BUFFER_LEN; i++)
  {
    //buff[i] = (byte) rand();
	data[i]=(byte) rand();
  }

  // Compute the 16-bit checksum
  //check = checksum(buff, BUFFER_LEN);
  check = checksum(data, BUFFER_LEN);

  // Output the checksum
  printf("checksum = %04X \n", check);
  return check;
  
}

//=============================================================================
//=  Compute Internet Checksum for count bytes beginning at location addr     =
//=============================================================================
word16 checksum(char *addr, word32 count)
{
  register word32 sum = 0;

  // Main summing loop
  while(count > 1)
  {
    //sum = sum + *((word16 *) addr)++;
	  sum += *((word16 *) addr)++;
    count = count - 2;
  }

  // Add left-over byte, if any
  if (count > 0)
    sum = sum + *((byte *) addr);

  // Fold 32-bit sum to 16 bits
  while (sum>>16)
    sum = (sum & 0xFFFF) + (sum >> 16);

  return(~sum);
}

This is mine header file(constant.h) which is included in socket.cpp
C++
int calc_check(int);
Tags: C++, C, VC++, Visual Studio

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900