Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c - Sepia Filter undefined reference to main?

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...