Visual Studio(2015)C项目依赖项-必须定义LNK1561入口点



我在一个C项目中有以下主程序,它(想法)使用了同一解决方案中的另一个项目的头和utils文件。上的头文件由utils文件中的函数声明组成(如下所示)

主要功能:

#include <stdio.h>
#include "header1C.h"
#include "utils_1C.c"
#include <stdbool.h>
int main() {
    int num = 0, base = 0, rKey; 
    do {
        bool chk = false; //flag for while loop to check if base is correct
        printf("nEnter number [Enter -1 to exit]: ");
        scanf_s("%d", &num); //number to be changed
        if (num != -1) {
            do {
                printf("Enter new base [2,4,8 or 16]: ");
                scanf_s("%d", &base); //new base [2,4,8,16]
             if ((base != 2) && (base != 4) && (base != 8) && (base != 16)){                  
                printf("Number must be either 2,4,8 or 16n");
                }
                else chk = true; //set flag to true
            } while (chk == false);
            newBase(num, base); //calls newBase() with parameters num and base
        }
        rKey = getchar(); //getchar to clear char buffer
        if (num == -1)
            printf("n[Press any key to exit]");
        rKey = getchar(); //readkey to exit programm on any key press
    } while (num != -1); //to be repeated until num entered by user is -1
return 0;
}

在一个名为Library的单独项目中:

头文件header1C.h:

char checkHex(int n);
void newBase(int n, int b);

实用程序文件utils_1C.c:

#include "header1C.h"
char checkHex(int n) { //used by newBase() - converts given number to letters if larger than 9
    switch (n) {
    case 10: return 'A';  //return A if n = 10
    case 11: return 'B';  //return B if n = 11
    case 12: return 'C';  //return C if n = 12
    case 13: return 'D';  //return D if n = 13
    case 14: return 'E';  //return E if n = 14
    case 15: return 'F';  //return F if n = 15
    }
    return n; //return given number if < 10
}
void newBase(int n, int b) {
    static char newNum[50];       //array in which the number is stored (array of remainders)
    int i = 0;                    //counter
    do {                          //long division and gathering of remainder
        newNum[i] = checkHex(n % b);  //calling checkHex() to check number and conert to letter if needed
        n = n / b; //divide n by b
        i++; //counter + 1
    } while (n >= b); //loop stops when n is smaller than it's divider b
    newNum[i] = checkHex(n); //calling checkHex()
    printf("nNumber in base %d: ", b); //flipped number - proper answer
    for (i; i >= 0; i--) { //loop stops when smaller than 0
        if ((newNum[i] >= 65) && (newNum[i] <= 70))  //check if newNum[i] is a letter [A-F]
            printf("%c", newNum[i]);  //output if letter
        else
            printf("%d", newNum[i]);  //output if number
    }
}

我得到这个错误:

错误LNK1561入口点必须为已定义库C:\Users。。。\分配\库\链接1

我已经将Library作为项目依赖项添加到具有主要功能的项目中,并且我还玩过

属性->配置属性->链接器->系统->子系统

以下是我在Stack Overflow上找到的其他答案,但运气不佳。

在这一点上,我不知道该怎么办,坦率地说,我不认为这会是一个这么大的问题(尽管我可能错过了什么?)

对这个长问题表示歉意,我们非常感谢您的帮助。

使用C++编译代码时,链接器需要int main()

当您将main()定义为返回void时,链接器找不到程序的入口点。

C++确实知道函数的返回类型,函数的签名,而不是C.

最新更新