为什么GCC说main有多个定义?我有一个主
Why is GCC saying multiple definitions of main? I have one main
我可以使用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函数。
相关文章:
- 在 C++ 中声明 const 对象需要用户定义的默认构造函数.如果我有一个可变成员变量,为什么不呢?
- 有没有办法声明一个公共静态常量,该常量将使用 constexpr 在源文件中定义(有什么区别)?
- 我对C++程序有一个未定义的参考,不知道如何处理它
- 我可以有一个从外部不可见但未在标头中定义的静态友元函数吗?
- 为什么复制构造函数不是微不足道的,因为有一个用户定义的析构函数?
- std::integral_constant<T, v>::value 总是有一个定义吗?
- 如何将包含多个.cpp源文件的文件夹导入Eclipse项目中,每个源文件都有一个main()定义
- mac构建有一个未定义的符号,而linux构建并没有用于相同的代码
- 为什么我有一个未定义的对友元函数的引用
- 我有一个为 cpp 中的某个类定义的模板函数 - 不是 hpp.可以由子类使用吗?
- 对于自定义类的一个未定义集,是否有一个默认的散列函数
- 我有一个指向自定义项的未初始化指针表,我想检查是否已经存在某些内容
- 重新定义strdup函数已经有一个Body
- 这是正常的 c++ 行为吗?编译器零初始化我的类,尽管有一个用户定义的构造函数
- C 是否有一个像 C++ 这样的定义规则
- LNK2005错误,已定义:可能有一个定义规则违反
- LoopFillZerobss对main有一个未定义的引用
- 休斯顿,我们有一个未定义的参考
- g++说我对一个函数有一个未定义的引用
- 是否定义有一个随机的循环终止条件?