undefined reference to `main' c language

Viewed 45

I tried compiling my code with:

gcc -Wall -pedantic -Werror -Wextra -std=gnu89 0-isupper.c -o 0-isuper

But its showing:

 /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

Here is the source code:

#include "main.h"

/**
*_isupper - checks for uppercase character
*_isupper - checks for uppercase character
*_isupper - checks for uppercase character
*@c: character to be checked
*Return: 1 if true, 0 if false
*/

int _isupper(int c)
{
    if (c >= 'A' && c <= 'Z')
    {
        return (1);
    }
    else
    {
       return (0);
    }
}
1 Answers

To successfully create a executable from C code, you need to implement the main() function. If you implemented main() elsewhere, then replace -o 0-isuper with -c flag so that it merely creates an object file. Subsequently, you can use ld to link 0-isuper.o with some other object file that implemented main() to create an executable.

Related