__cdecl LNK 2019 VS2010 C

__cdecl LNK 2019 VS2010 C

我正在尝试用 C (VS2010) 实现一些简单的功能。应该很容易。但是,我收到

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

这两个函数虽然在我创建第一个函数(Ex1)时它起作用了..声明和原型对我来说看起来不错.. 只有一个 C 文件,里面有函数。 我很乐意提供任何建议。

#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;
}

非常抱歉,我无法重现相同的错误消息。

下面提到了可能会发生此问题的最常见错误。

请检查您是否选择了 "new Win32 application" 而不是 "new Win32 console application"。

还有多种原因会导致链接器出现问题。请彻底检查您的代码。