Linking a DLL using xerces gives undefined symbols

左心房为你撑大大i 提交于 2020-01-04 06:20:10

问题


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.

For example:

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;
}

Linking:

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

When linking the library, I get:

/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'

...


回答1:


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 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

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.



来源:https://stackoverflow.com/questions/16820453/linking-a-dll-using-xerces-gives-undefined-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!