2014-02-22 61 views
0

我想在我的项目中使用SDL_image但我不能让过去此错误消息C++的libtiff:未定义参考_TIFFerrorHandler

||=== Build: Win32 Release in Sandbox (compiler: GNU GCC Compiler) ===| 
..\lib\mingw32\libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'| 
..\lib\mingw32\libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'| 
..\lib\mingw32\libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'| 
..\lib\mingw32\libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'| 
||error: ld returned 1 exit status| 
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===| 

起初我不确定参考_TIFFmalloc,_TIFFrealloc等,但我通过创建一个源文件并将其添加到项目中来修复它们。

tif_fix.c

// This file is intended to fix the "undefined reference..." errors 

#include <stdlib.h> 
#include <string.h> 

#include "tiffio.h" 

void* _TIFFmalloc(tmsize_t s) 
{ 
    return malloc(s); 
} 

void* _TIFFrealloc(void* p, tmsize_t s) 
{ 
    return realloc(p, s); 
} 

void _TIFFmemset(void* p, int v, tmsize_t c) 
{ 
    memset(p, v, c); 
} 

void _TIFFmemcpy(void* d, const void* s, tmsize_t c) 
{ 
    memcpy(d, s, c); 
} 
int _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) 
{ 
    return memcmp(p1, p2, c); 
} 

void _TIFFfree(void* p) 
{ 
    free(p); 
} 

所有SDL_image所需的库编译为静态库(zlib的,使用libpng,libjpeg,libwebp的libtiff4和),甚至SDL_image被编译为静态的。

我已经定义LOAD_BMP,LOAD_GIF,LOAD_JPG,LOAD_LBM,LOAD_PCX,LOAD_PNG,LOAD_PNM,LOAD_TGA,LOAD_TIF,LOAD_WEBP,LOAD_XCF,LOAD_XPM,LOAD_XV,LOAD_XXX在SDL_image项目,使图书馆。 SDL_image和库都可以毫无问题地编译。

但是,当我将SDL_image和库链接到我的应用程序的项目并尝试编译SDL_image提供的示例showimage.c时,我得到未定义的引用...错误消息。

我试图重新排序库中的代码:: Blocks的项目,因为我知道这个顺序与MinGW的重要(我用MinGW的4.8.2 X86)。到目前为止,没有任何工作,我没有想法。

回答

0

我能够修复错误,并最终通过增加两个新的功能到tif_fix.c文件使编译应用程序和工作:

static void msdosWarningHandler(const char* module, const char* fmt, va_list ap) 
{ 
    // Do not handle warnings 
} 

TIFFErrorHandler _TIFFwarningHandler = msdosWarningHandler; 

static void msdosErrorHandler(const char* module, const char* fmt, va_list ap) { 

    // use this for diagnostic only (do not use otherwise, even in DEBUG mode) 
    /* 
    if (module != NULL) { 
     char msg[1024]; 
     vsprintf(msg, fmt, ap); 
     FreeImage_OutputMessageProc(s_format_id, "%s: %s", module, msg); 
    } 
    */ 
} 

TIFFErrorHandler _TIFFerrorHandler = msdosErrorHandler; 

我发现他们在FreeImage的> PluginTIFF.cpp文件所以这个功劳归功于FreeImage。

编辑: 通过手动搜索LibTiff4库文件后,我在Changelog文件中发现了一些信息,显然有libtiff/tif_ {unix,vms,win32} .c,它们已经实现,但文件不是包含在我的Code :: Blocks项目中。