使用xerces链接DLL会产生未定义的符号 [英] Linking a DLL using xerces gives undefined symbols

查看:221
本文介绍了使用xerces链接DLL会产生未定义的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cygwin创建一个共享库/ DLL使用Xerces。当我从主应用程序调用xercesc函数时,一切都很好,但是当我尝试将一些代码放入库中时,我得到未定义的符号为xerxesc定义的所有静态东西。

I'm creating a shared library/DLL using cygwin which makes use of Xerces. When I call the xercesc functions from the main application everything is fine, but when I try to put some code into the library, then I get undefined symbols for all the static stuff that xerxesc defines.

例如:

std::string fromXMLString(XMLCh *oXMLString)
{
    std::string result;
    xercesc::DOMImplementation *impl =  xercesc::DOMImplementationRegistry::getDOMImplementation(X("Core"));

    char *temp = xercesc::XMLString::transcode(oXMLString);
    result = temp;

    xercesc::XMLString::release(&temp);
    return result;
}

链接:

g++ -shared -Wl,-soname,cygsupport.so  -L /usr/local/lib -l xerces-c -o cygsupport.so obj/helper/xml_helper.o 

链接库时,我会得到:

/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::DOMImplementationRegistry::getDOMImplementation(wchar_t const*)'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLString::transcode(wchar_t const*, xercesc_3_1::MemoryManager*)'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLString::release(char**, xercesc_3_1::MemoryManager*)'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLString::release(wchar_t**, xercesc_3_1::MemoryManager*)'
/usr/local/include/xercesc/internal/XSerializable.hpp:37: undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'

...

推荐答案

最后经过几天研究这个问题,我找到了解决方案。

Finally after several days on looking into this issue I found the solution. It is as simple as stupid.

我原来的链接器命令行看起来像这样:

My original linker commandline looked like this:

g++ -shared -o mylib.so -L/usr/local/lib -lxerces-c objects...

Googling这个问题没有产生任何有用的,所以最后我决定创建一个新的示例项目与eclipse,突然它工作。唯一的区别是链接器的命令行。当我将相同的命令应用到我的主项目时,它突然编译。

Googling on this problem didn't yield anything usefull, so finally I decided to create a fresh new sample project with eclipse and suddenly it worked. The only difference was in the commandline to the linker. When I applied the same order to my main project it suddenly compiled.

g++ -L/usr/local/lib -shared -o mylib.so objects... -lxerces-c

请注意,在上面的行中,来到图书馆之前,毫不奇怪这使得差别。我认为libs的顺序只适用于库,但显然也必须适当地排序对象。

Note that in the above line, the objects come before the library, and apperently this makes the difference. I thought that the ordering of the libs only applies to the libraries, but apparently also the objects must be ordered appropriately.

这篇关于使用xerces链接DLL会产生未定义的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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