为什么GCC说main有多个定义?我有一个主

Why is GCC saying multiple definitions of main? I have one main

本文关键字:定义 有一个 GCC main 为什么      更新时间:2023-10-16

我可以使用microsoft visual studio成功地运行和编译我的代码。当我尝试使用gcc编译它以通过SSH提交我的程序时,我得到一个错误,说main有多个定义。我只有一个main函数,我没有在任何地方调用main函数。

下面是编译器的错误信息:

/tmp/ccsoZK9a.o: In function `main':
ipc_ms1_prof.c:(.text+0x0): multiple definition of `main'
/tmp/cciG56p6.o:ipc_ms1.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
下面是我的代码:
#include <stdio.h>
//Prototype Functions
void welcome(void);
void prnTitle();
void prnFooter(double gTotal);
void clrKyb(void);
void pause(void);
int getInt(void);
int getIntLimited(int lowerLimit, int upperLimit);
double getDbl(void);
double getDblLimited(double lowerLimit, double upperLimit);
int main(void)
{
int iVal = 0;
double dVal = 0.00;
welcome();
printf("listing header and footer with grand total:n");
prnTitle();
prnFooter(1234.5678);
printf("listing header and footer without grand total:n");
prnTitle();
prnFooter(-1);
pause();
printf("Enter an integer: ");
iVal = getInt();
printf("You entered: %dn", iVal);
printf("Enter an integer between 10 an 20: ");
iVal = getIntLimited(10, 20);
printf("Your entered %dn", iVal);
printf("Enter a floating point number: ");
dVal = getDbl();
printf("You entered: %0.2lfn", dVal);
printf("Enter a floating point number between 10.00 and 20.00: ");
dVal = getDblLimited(10.0, 20.0);
printf("You entered: %0.2lfn", dVal);
printf("End of tester program for milestone one!n");
return 0;
}
void welcome(void)
{
printf("---=== Grocery Inventory System ===---nn");
}
void prnTitle()
{
printf("Row |SKU| Name               | Price  |Taxed| Qty | Min |   Total            |Atnn");
printf("----+---+--------------------+--------+-----+-----+-----+------------|---n");
}
void prnFooter(double gTotal)
{
printf("--------------------------------------------------------+----------------n");
if (gTotal > 0)
    printf("                                           Grand Total: |     %12.2lfn", gTotal);
}
void clrKyb(void)
{
char input = ' ';
//Keep getting user input as long as input is not equal to enter('n')
do
{
    scanf("%c", &input);
} while (input != 'n');
}
void pause(void)
{//Pause the program as until the user presses enter
printf("Press <ENTER> to continue...");
clrKyb();
}
int getInt(void)
{
char NL = 'x';//NL is x because that is one char whereas a number would be     int                                          
int value;
while (NL != 'n') {
    //loop is broken if not n so it is routed to another loop to keep loop going until n
    scanf("%d%c", &value, &NL);
    if (NL != 'n') {
        clrKyb();
        printf("Invalid integer, please try again: ");
    }
}
return value;
}
int getIntLimited(int lowerLimit, int upperLimit)
{
int value = 0;
value = getInt();
while (value < lowerLimit || value > upperLimit)
{//while user input is not within the right numerical range
    //Display error message
    printf("Invalid value, %d < value < %d: ", lowerLimit, upperLimit);
    value = getInt();//call getInt to get user input again
}
return value;
}
double getDbl(void)//Similar to getInt.. double version
{
char NL = 'x';
double value;
while (NL != 'n') {
    scanf("%lf%c", &value, &NL);
    if (NL != 'n') {
        clrKyb();
        printf("Invalid integer, please try again: ");
    }
}
return value;
}
double getDblLimited(double lowerLimit, double upperLimit)
{
double value = 0;
value = getDbl();
while (value < lowerLimit || value > upperLimit)
{
    printf("Invalid value, %lf < value < %lf: ", lowerLimit, upperLimit);
    value = getDbl();
}
return value;
}//Similar to getIntLimited but the double version

检查链接。通常这意味着另一个目标文件同时被编译,该文件也包含main函数。

相关文章: