C++LibTiff:对_TIFFerrorHandler的未定义引用
C++ LibTiff: undefined reference to _TIFFerrorHandler
我正试图在我的项目中使用SDL_image,但我无法通过此错误消息
||=== Build: Win32 Release in Sandbox (compiler: GNU GCC Compiler) ===|
..libmingw32libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'|
..libmingw32libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'|
..libmingw32libtiff4.a(tif_error.o):tif_error.c|| undefined reference to `_TIFFerrorHandler'|
..libmingw32libtiff4.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)) ===|
起初,我得到了对_TIFFalloc、_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_iimage也编译为静态。
我在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_iimage提供的示例showimage.c时,我得到了对…错误消息的未定义引用。
我尝试重新排序Code::Blocks项目中的库,因为我知道顺序对MinGW很重要(我使用的是MinGW 4.8.2 x86)。到目前为止,一切都不起作用,我也没什么想法。
我能够修复错误,并通过在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实现了它们,但我的代码::块项目中没有包含该文件。
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用