質問

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'

...

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top