【发布时间】:2021-12-23 01:00:43
【问题描述】:
也许有人可以给我一个提示:
我已经尝试修复此错误几个小时,但不知何故找不到真正的问题。会不会是其他文件之一(filter.c 或 bmp.h)有问题?
我收到以下错误消息:
/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**
我做错了什么?
#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;
}
【问题讨论】:
-
如果你正在编译一个可执行文件,它必须有一个名为
main的函数。这将在程序启动时调用。你是否有一个?不在您共享的代码中。 -
如果你正在编译一个库,你必须告诉编译器这就是你正在做的事情。我们将不得不讨论编译器和/或链接器标志。