我正在使用无头图像并在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
如何修复此链接器问题?
答案 0 :(得分:0)
ilInit
,ilGenImages
等在哪里定义?那是 - 哪个源文件/预编译库保存它们?
您需要将该信息提供给cc。
假设这些是在名为foo.c
的源文件中定义的,解决方案将是:
cc display.c foo.c -o display
在进一步的细节中,当编译器为您的函数(在头文件中)具有正确的声明时,此错误会上升,但是找不到定义(实际二进制文件或创建该二进制文件的源)。