C 乌贼墨过滤器未定义对主过滤器的引用?
我正在处理一个项目,但由于某种原因,我的代码无法编译,它会打印错误消息C 乌贼墨过滤器未定义对主过滤器的引用?,c,C,我正在处理一个项目,但由于某种原因,我的代码无法编译,它会打印错误消息 ''' /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
''' /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 '''
我看不出有任何问题,这是我的代码,我非常感谢您的帮助
我的代码
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;
}
void-sepia(int-height,int-width,rgb三重图像[height][width])
{
//超高
对于(int h=0;h255 | | sepiaGreen>255 | | sepiaBlue>255)
{
sepired=255;
sepiaGreen=255;
sepiaBlue=255;
}
图像[h][w].rgbtRed=(sepired);
图像[h][w].rgbtBlue=(深蓝色);
图像[h][w].rgbtGreen=(sepiaGreen);
}
}
返回;
}
您已经确定了主要问题:未定义对main的引用
每个构建到应用程序(独立可执行文件)中的C程序都需要一个定义。这个简单的方法将允许您在此处成功构建可执行文件:
给定结构定义为:
typedef struct {
double rgbtRed;
double rgbtGreen;
double rgbtBlue;
}RGBTRIPLE;
RGBTRIPLE image[3][4];//due to the design of sepia, this must be globally defined.
那么,编译器将不会出错的最简单的主函数是:
int main(void)
{
sepia(3, 4, image);
return 0;
}
如评论中所述,需要对功能sepia进行一些调整。例如,该声明:
int sepiaRed = .393 ...
double sepiaRed = .393 * image[h][w].rgbtRed + .769 * image[h][w].rgbtGreen + .189 * image[h][w].rgbtBlue;
使用int
类型存储double
值。这将编译,但会导致运行时错误。将所有这些语句的int
更改为double就是一个开始。但也存在其他问题
如果需要其他帮助,请留下注释,或者使用调试器遍历代码以查看错误并根据需要进行调整
例如,对于未初始化的图像
结构,此语句的结果是什么:
int sepiaRed = .393 ...
double sepiaRed = .393 * image[h][w].rgbtRed + .769 * image[h][w].rgbtGreen + .189 * image[h][w].rgbtBlue;
如果你的程序是一个独立的可执行程序,它需要一个
main
例程,而你的代码没有这个例程。如果您的代码要与提供main
例程的其他代码一起使用,则必须链接到该代码。为了帮助您,我们必须知道您想要实现什么以及如何构建您的程序。(不相关的旁注:您应该单独检查组件上的范围溢出。现在的情况是,如果三个组件中的任何一个超过最大值,您的代码将显示一个白色像素。)