-1

I am working on a project but for some reason my code will not compile and it prints the error message.

''' /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o: In function 
`_start': (.text+0x20): undefined reference to `main' clang-7: error: linker command failed 
with exit code 1 (use -v to see invocation) <builtin>: recipe for target 'helpers' failed 
make: *** [helpers] Error 1 '''

With an emphasis on

undefined reference to 'main'. 

I don't see any problems here's my code and i'd appreciate any help.

MY CODE

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    // over height
    for (int h = 0; h < height; h++)
    {
        // over width
        for ( int w = 0; w < width; w++)
        {
            int sepiaRed = .393 *  image[h][w].rgbtRed + .769 *  image[h][w].rgbtGreen + .189 *  image[h][w].rgbtBlue;
            int sepiaGreen = .349 *  image[h][w].rgbtRed + .686 *  image[h][w].rgbtGreen + .168 *  image[h][w].rgbtBlue;
            int sepiaBlue = .272 *  image[h][w].rgbtRed + .534 *  image[h][w].rgbtGreen + .131 *  image[h][w].rgbtBlue;
            // space
            if (sepiaRed > 255 || sepiaGreen > 255 || sepiaBlue > 255)
            {
                sepiaRed = 255;
                sepiaGreen = 255;
                sepiaBlue = 255;
            }

            image[h][w].rgbtRed = (sepiaRed);
            image[h][w].rgbtBlue = (sepiaBlue);
            image[h][w].rgbtGreen = (sepiaGreen);
        }
    }
    return;
}
Steve Friedl
  • 3,929
  • 1
  • 23
  • 30
  • If your program is a standalone executable, it needs a `main` routine, which your code doesn't have. If your code is to be used with other code that provides a `main` routine, you must link to that code. In oder to help you, we must know what you want to achieve and how you build your program. – M Oehm Apr 27 '20 at 13:05
  • (Unrelated side note: You should check for range overflow on the compoments individually. The way it is now, your code will show a white pixel if any of the three components exceed the maximum.) – M Oehm Apr 27 '20 at 13:07

1 Answers1

0

You've identified the main problem: undefined reference to _main_ Every C program being built into an application (standalone executable) needs one by definition. This simple one will allow you to build your executable successfully here:

Given the struct is defined as:

typedef struct {
    double rgbtRed;
    double rgbtGreen;
    double rgbtBlue;
}RGBTRIPLE;  

RGBTRIPLE image[3][4];//due to the design of sepia, this must be globally defined.

Then the simplest main function that will compiler without error is:

int main(void)
{
    sepia(3, 4, image);

    return 0;
}

As mentioned in comments, there are some adjustments to the function sepia that are required. For example, that statement:

int sepiaRed = .393 ... 

uses an int type to store double values. This will compile, but will result in runtime errors. Changing int to double for all of these statements is a start. But there are other problems as well.

Leave a comment if you would like additional help, or use a debugger to walk through the code to see the errors and make adjustments as needed.

For example, for an uninitialized image struct, what will be the result of this statement:

double sepiaRed = .393 *  image[h][w].rgbtRed + .769 *  image[h][w].rgbtGreen + .189 *  image[h][w].rgbtBlue;
ryyker
  • 22,849
  • 3
  • 43
  • 87