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

时间:2016-10-30 02:41:24

标签: c++ c gcc

我可以使用microsoft visual studio成功运行和编译我的代码。当我尝试使用gcc编译它来通过SSH提交我的程序时,我得到一个错误,说明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: %d\n", iVal);

printf("Enter an integer between 10 an 20: ");
iVal = getIntLimited(10, 20);
printf("Your entered %d\n", iVal);

printf("Enter a floating point number: ");
dVal = getDbl();
printf("You entered: %0.2lf\n", dVal);

printf("Enter a floating point number between 10.00 and 20.00: ");
dVal = getDblLimited(10.0, 20.0);
printf("You entered: %0.2lf\n", dVal);

printf("End of tester program for milestone one!\n");

return 0;
}

void welcome(void)
{
printf("---=== Grocery Inventory System ===---\n\n");
}
void prnTitle()
{
printf("Row |SKU| Name               | Price  |Taxed| Qty | Min |   Total            |Atn\n");
printf("----+---+--------------------+--------+-----+-----+-----+------------|---\n");
}
void prnFooter(double gTotal)
{
printf("--------------------------------------------------------+----------------\n");
if (gTotal > 0)
    printf("                                           Grand Total: |     %12.2lf\n", 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

1 个答案:

答案 0 :(得分:3)

检查链接器。通常这意味着同时编译另一个目标文件,该文件也包含一个main函数。所有相关文件中只能有一个主要功能。