使错误未定义参考

make errors undefined reference to

我正在使用无头图像并在 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

我该如何解决这个链接器问题?

ilInitilGenImages等定义在哪里?那就是 - 哪个来源 file/pre-compiled 图书馆拥有它们? 您需要将该信息提供给 cc.

假设这些在名为 foo.c 的源文件中定义,解决方案将是:

cc display.c foo.c -o display

更详细地说,当编译器对您的函数有正确的声明(在您的头文件中),但没有找到定义(实际的二进制文件或创建该二进制文件的源代码)时,会出现此错误。