我正在使用一个无头图像,并在GNU bash中编译这个简单的代码。我收到这些链接错误
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
ILuint ImgId;
// Initialize DevIL.
ilInit();
// Generate the main image name to use.
ilGenImages(1, &ImgId);
// Bind this image name.
ilBindImage(ImgId);
// Loads the image specified by File into the image named by ImgId.
if (!ilLoadImage(argv[1])) {
printf("Could not open file...exiting.\n");
return 3;
}
// Display the image's dimensions to the end user.
printf("Width: %d Height: %d Depth: %d Bpp: %d\n",
ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_DEPTH),
ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));
return 0;
}root@parallella:/home/parallella/parallella-examples/lena# make display
cc display.c -o display
/tmp/ccSqb23j.o: In function `main':
display.c:(.text+0xa): undefined reference to `ilInit'
display.c:(.text+0x16): undefined reference to `ilGenImages'
display.c:(.text+0x1e): undefined reference to `ilBindImage'
display.c:(.text+0x2a): undefined reference to `ilLoadImage'
display.c:(.text+0x48): undefined reference to `ilGetInteger'
display.c:(.text+0x52): undefined reference to `ilGetInteger'
display.c:(.text+0x5c): undefined reference to `ilGetInteger'
display.c:(.text+0x66): undefined reference to `ilGetInteger'
collect2: error: ld returned 1 exit status
make: *** [display] Error 1我怎样才能解决链接器的问题?
发布于 2015-09-29 09:04:30
在哪里定义了ilInit、ilGenImages等?也就是说-哪个源文件/预编译库保存它们?您需要将该信息提供给cc。
假设这些文件是在名为foo.c的源文件中定义的,则解决方案如下:
cc display.c foo.c -o display
在进一步的详细信息中,当编译器对您的函数(在头文件中)有正确的声明时,这个错误会上升,但是没有找到任何定义(创建该二进制文件的实际二进制或源)。
https://stackoverflow.com/questions/32839829
复制相似问题