__cdecl LNK 2019 VS2010 C

207 views Asked by At

I am trying to implement a few simple functions in C (VS2010). Should be very easy. BUT, I am receiving

error LNK2019: unresolved external symbol "1>test01.obj : error LNK2019: unresolved external symbol "int __cdecl Ex2(int,int)" (?Ex2@@YAHHH@Z) referenced in function _main 1>test01.obj : error LNK2019: unresolved external symbol "void __cdecl Ex1(int *,int)" (?Ex1@@YAXPAHH@Z) referenced in function _main

for both functions although it worked when I've created the first function (Ex1).. Declaration and prototypes looking good to me.. There is only one C file with functions in it. I'll be glad for any advice.

#include <stdio.h>

//Function prototypes/////////////////////////////////

void Ex1(int*, int);
int Ex2(int, int);

///////////////////////////////////////////////////// 

int main()
{
  int select = 0, i, all_Ex_in_loop = 0, arrsize = 0;
  int a = -3, b = 13; // EX 2 variables

  int* arrPtr;              //EX1 definitions
  int arr[] =
  { 7, 5, -8, 3, 4, 21, -10, -3, 2, 4 };
  arrsize = sizeof(arr) / sizeof(int);
  arrPtr = arr;

  printf(
      "Run menu once or cyclically?\n(Once - enter 0, cyclically - enter other number) ");
  if (scanf_s("%d", &all_Ex_in_loop) == 1)
    do
    {
      for (i = 1; i <= 5; i++)
        printf("Ex%d--->%d\n", i, i);
      printf("EXIT-->0\n");
      do
      {
        select = 0;
        printf("please select 0-5 : ");
        scanf_s("%d", &select);
      } while ((select < 0) || (select > 5));
      switch (select)
      {
      case 1:
        Ex1(arrPtr, arrsize);
        break;
      case 2:
        Ex2(a, b);
        break;
//case 3: Ex3(); break;
//case 4: Ex4(); break;
//case 5: Ex5(); break;
      }
    } while (all_Ex_in_loop && select);
  return 0;
}

// ---------------------------------------------- EX1 -------------------------------------------------------------
void Ex1(int* ptr, int size)
{
  int i;

  printf("Original array: ");
  for (i = 0; i < size; i++)
  {
    printf("%d, ", ptr[i]);
  }
  for (i = 1; i < size; i++)
  {
    ptr[i] += ptr[i - 1];
  }

  printf("\n Updated array: ");
  for (i = 0; i < size; i++)
  {
    printf("%d, ", ptr[i]);
  }
  printf("\n");

}

//---------------------------------------------------------------- EX2 ------------------------------------------------------------

int Ex2(int a, int b)
{
  int firstVal = 0, secVal = 0, num = 0;

  printf("Please enter numbers. -1 to finish: ");
  while (num != -1)
  {
    scanf_s("%d", &num);
    if (num > (a + b) / 2 && num < b)
    {
      firstVal += num;
    }
    if (num > a && num < (a + b) / 2)
    {
      secVal += num;
    }
  }

  printf("\n The value is: %d", firstVal + secVal);

  return firstVal + secVal;
}
1

There are 1 answers

2
Vimal Bhaskar On BEST ANSWER

Extremely sorry as i couldnt reproduce the same error message.

The most common error for which this issue would have happened is mentioned below.

Please check if you have selected "new Win32 application" instead of "new Win32 console application".

Also there are multiple causes due to which the linker issues would come out. Please check your code thoroughly.