简体   繁体   English

使错误未定义引用

[英]make errors undefined reference to

I'm using a headless image and compiling this simple code in GNU bash. 我正在使用无头图像,并在GNU bash中编译此简单代码。 I receive these linker errors 我收到这些链接器错误

#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

How can I fix this linker problem? 如何解决此链接器问题?

Where are ilInit , ilGenImages , etc. defined? ilInitilGenImages等在哪里定义? That is - which source file/pre-compiled library holds them? 那就是-哪个源文件/预编译的库保存它们? You need to provide that information to cc. 您需要将该信息提供给抄送。

Assuming these are defined in a source file called foo.c , the solution will be: 假设这些是在名为foo.c的源文件中定义的,则解决方案将是:

cc display.c foo.c -o display

In further details, this error rises when the compiler has the correct declarations for your functions (in your header files), but no definition (actual binary or sources to create that binary) are found. 更详细地讲,当编译器为您的函数(在头文件中)具有正确的声明但未找到定义(实际的二进制文件或创建该二进制文件的源代码)时,此错误会增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM