mingw/libxml2问题 [英] mingw/libxml2 issue

查看:131
本文介绍了mingw/libxml2问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在win7下的mingw中使用libxml2(v2.2.6.0) 我添加了lib -llibmlx2,但是每次编译时我都会得到:

I'm trying to use libxml2 (v2.2.6.0) with mingw under win7 I added the lib -llibmlx2, but each time I compile I get :

error: undefined reference to `_imp__xmlFree'

在Google上,我发现了这一点: http://osdir.com/ml/gnome.lib .xml.ge .../msg00003.html
但是仍然不起作用.

On Google I found this: http://osdir.com/ml/gnome.lib.xml.ge.../msg00003.html
But still doesn't work.

有什么主意吗?

谢谢...

推荐答案

我相信只有在使用由Igor Zlatovic准备的预编译libxml2二进制文件时,才会出现此问题.我怀疑如果使用由mingw本地编译的libxml2 lib,问题就消失了.

I believe that this problem only happens when using precompiled libxml2 binaries prepared by Igor Zlatovic. I suspect that the problem goes away if using libxml2 lib natively compiled with mingw.

这是libxml/globals.h中xmlFree的声明:

Here is the declaration of xmlFree in libxml/globals.h:

#else /* !LIBXML_THREAD_ALLOC_ENABLED */
XMLPUBVAR xmlMallocFunc xmlMalloc;
XMLPUBVAR xmlMallocFunc xmlMallocAtomic;
XMLPUBVAR xmlReallocFunc xmlRealloc;
XMLPUBVAR xmlFreeFunc xmlFree;
XMLPUBVAR xmlStrdupFunc xmlMemStrdup;
#endif /* LIBXML_THREAD_ALLOC_ENABLED */

和XMLPUBVAR扩展为

and XMLPUBVAR is expanded by

#define XMLPUBVAR __declspec(dllimport) extern

来自libxml/xmlexports.h

from libxml/xmlexports.h

首次观察. xmlFree不是函数,而是变量.这是一个例外,因为几乎所有其他libxml2函数都是真实的导出函数.这就解释了为什么xmlFree()是人们遇到的唯一有问题的功能.

First observation. xmlFree is not a function but a variable. This is an exceptional occurrence as almost all the other libxml2 functions are real exported functions. This explain why xmlFree() is the only problematic function encountered by people.

mingw编译器将导入的符号名称从xmlFree更改为_imp__xmlFree,这在libxml2.lib中找不到.我猜想对于其他编译器(例如MSVC),链接器将搜索libxml2.lib中找到的正确符号_xmlFree:

mingw compiler change the imported symbol name from xmlFree to _imp__xmlFree which is not found in libxml2.lib. I am guessing that with other compilers such as MSVC, the linker is instead searching for the correct symbol _xmlFree found inside libxml2.lib:

C:\MinGW\msys\1.0\home\100517891\embedded\ext\libxml2\lib>"c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\dumpbin.exe" /exports libxml2.lib | grep xmlFree
              _xmlFree
              _xmlFreeAttributeTable
              _xmlFreeAutomata
              _xmlFreeCatalog
              _xmlFreeDoc
              _xmlFreeDocElementContent
              _xmlFreeDtd
              _xmlFreeElementContent
              _xmlFreeElementTable
              _xmlFreeEntitiesTable
              _xmlFreeEnumeration
              _xmlFreeIDTable
              _xmlFreeInputStream
              _xmlFreeMutex
              _xmlFreeNode
              _xmlFreeNodeList
              _xmlFreeNotationTable
              _xmlFreeNs
              _xmlFreeNsList
              _xmlFreeParserCtxt
              _xmlFreeParserInputBuffer
              _xmlFreePattern
              _xmlFreePatternList
              _xmlFreeProp
              _xmlFreePropList
              _xmlFreeRMutex
              _xmlFreeRefTable
              _xmlFreeStreamCtxt
              _xmlFreeTextReader
              _xmlFreeTextWriter
              _xmlFreeURI
              _xmlFreeValidCtxt

我还没有找到任何解决链接错误的方法,但是解决该问题的一种简单而安全的方法是确认xmlFree是一个简单的函数指针变量,该变量已初始化为全局变量中标准free()函数的地址. .c,更改分配的唯一方法是使用一些调试开关重新编译dll.

I have not found any way to fix the linkage error but a simple and safe way to workaround the problem is to acknowledge the fact that xmlFree is a simple function pointer variable initialized to the address of the standard free() function in globals.c and the only way to change that assignation is to recompile the dll with some debug switches.

随意将对xmlFree()的调用替换为对free()的调用.一切都应该很好,并且连接错误将消失.

Feel free to replace calls to xmlFree() with calls to free(). Everything should be fine and the linkage error will go away.

这篇关于mingw/libxml2问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆