Maybe someone can give me a hint:
I have been trying to fix this error for several hours but somehow couldn't find the real issue. Could it be, that there is an issue with one of the other files (filter.c or bmp.h)?
I reiceive the following error message:
/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: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [<builtin>: helpers] Error 1**
What am I doing wrong?
#include <math.h>
#include "helpers.h"
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; height > i; i )
{
for (int j = 0; width > j; j )
{
//dividing by 3 in order to get average color / grey tone
// using float
// using round
float total = image[i][j].rgbtGreen image[i][j].rgbtRed image[i][j].rgbtBlue;
int average = (round)(total / 3); // 3 because of 3 colors RGB / Red, Green, Blue
average = image[i][j].rgbtGreen = image[i][j].rgbtRed = image[i][j].rgbtBlue;
}
}
}
// Convert image to sepia
// Maximalwert von 255 Beachten --> hier am besten if condition > 255 dann etc
// round beachten // siehe hint
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; height > i; i )
{
for (int j = 0; width > j; j )
{
float green_before = image[i][j].rgbtGreen;
float red_before = image[i][j].rgbtRed;
float blue_before = image[i][j].rgbtBlue;
int green_after = (round)(.349 * red_before .686 * green_before .168 * blue_before);
int red_after = (round)(.393 * red_before .769 * green_before .189 * blue_before);
int blue_after = (round)(.272 * red_before .534 * green_before .131 * blue_before);
if (green_after > 255)
{
green_after = 255;
}
if (red_after > 255)
{
red_after = 255;
}
if (blue_after > 255)
{
blue_after = 255;
}
image[i][j].rgbtGreen = green_after;
image[i][j].rgbtRed = red_after;
image[i][j].rgbtBlue = blue_after;
}
}
}
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; height > i; i )
{
for (int j = 0; j < width / 2; j )
{
RGBTRIPLE temp = image[i][j];
image[i][j] = image[i][width - j - 1];
image[i][width - j - 1] = temp;
}
}
}
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE temp[height][width];
for (int i = 0; height > i; i )
{
for (int j = 0; width > j; j )
{
int Green_insg = 0;
int Red_insg = 0;
int Blue_insg = 0;
float counter = 0;
for (int a = -1; 2 > a; a )
{
for (int b = -1; 2 > b; b )
{
if (0 > i a || i a > height - 1 || 0 > j b || j b > width -1)
{
continue;
}
Green_insg = image [i a][j b].rgbtGreen;
Red_insg = image [i a][j b].rgbtRed;
Blue_insg = image [i a][j b].rgbtBlue;
counter ;
}
}
// Durchschnittswerte der Nachbarpixel bilden
temp[i][j].rgbtGreen = round(Green_insg/counter);
temp[i][j].rgbtRed = round(Red_insg/counter);
temp[i][j].rgbtBlue = round(Blue_insg/counter);
}
}
for (int i = 0; height > i; i )
{
for (int j = 0; width > j; j )
{
image[i][j].rgbtGreen = temp[i][j].rgbtGreen;
image[i][j].rgbtRed = temp[i][j].rgbtRed;
image[i][j].rgbtBlue = temp[i][j].rgbtBlue;
}
}
return;
}
CodePudding user response:
You compiled some C
code without telling gcc
what kind of output you want. When you do this, gcc
will use a default setting, believing you want a runnable executable.
All runnable executables must have a entry point. That entry point has a signature (a very specific function, with very specific types). The signature required for main
in a running executable should be written like this:
int main(int argc, char** argv) {
...
}
Note that the ...
is not part of the C language, and should not be typed; rather the code you want executed should be typed there instead of typing ...
If you wanted to not build an executable, there are other options available. I won't list all of them, but a common one is:
-c
This halts compilation before linking, and writes a '.o' file, meaning if you were compiling hello.c
you would get the output hello.o
(which can't be executed, but can be combined easily into another executable (by linking) or can be combined into an archive collection.a
(useful for passing lots of compiled items to other exectuables, as in when testing) or a shared library collection.so
which is useful for a library purposefully built to be shared with other programs, or loaded by your own program optionally.
Since we don't know what you wanted gcc
to do, hopefully it is coverer above; but, if it is not covered above, please submit a new question with more details.