【问题标题】:Linker error: undefined reference to `main'链接器错误:未定义对“主”的引用
【发布时间】:2021-01-29 01:15:05
【问题描述】:
#include <cs50.h>
#include <stdio.h>

bool maths (int a, int b, int c)
{
    int first = a + b;
    int second = b + c;
    int third = c + a;
    if (first <= c)
    {
        return false;
    }
    else if (second <= a)
    {
        return false;
    }
    else if (third <= b)
    {
        return false;
    }
    else
    {
        return true;
    }
}

我在尝试编译时收到错误消息undefined reference to `main'。我试图查找此错误消息,但我发现的东西超出了我的想象。谁能向像我这样的新手解释我做错了什么?

$ clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    triangle.c  -lcrypt -lcs50 -lm -o triangle
/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [<builtin>: triangle] Error 1

【问题讨论】:

    标签: c function cs50


    【解决方案1】:

    您的程序中似乎缺少main 函数。

    #include <cs50.h>
    #include <stdio.h>
    
    bool maths (int a, int b, int c)
    {
        int first = a + b;
        int second = b + c;
        int third = c + a;
        if (first <= c)
        {
            return false;
        }
        else if (second <= a)
        {
            return false;
        }
        else if (third <= b)
        {
            return false;
            }
        else
        {
            return true;
        }
    }
    
    int main ()
    {
      maths(1,2,3);
    
      return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多