构建 xerces-c 3.2.4 并使用最小的 main.cpp 后:
// Other include files, declarations, and non-Xerces-C++ initializations.
using namespace xercesc;
int main(int argc, char* argv[])
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
// Do your failure processing here
return 1;
}
// Do your actual work with Xerces-C++ here.
XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
我遇到 ld 失败,找不到 xerces 参考资料:
$ g++ -L/usr/local/lib -lxerces-c bogus.cpp -obogus
/usr/bin/ld: /tmp/ccpI29iy.o: in function `main':
bogus.cpp:(.text+0x26): undefined reference to `xercesc_3_2::XMLUni::fgXercescDefaultLocale'
/usr/bin/ld: bogus.cpp:(.text+0x2e): undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)'
/usr/bin/ld: bogus.cpp:(.text+0x33): undefined reference to `xercesc_3_2::XMLPlatformUtils::Terminate()'
/usr/bin/ld: /tmp/ccpI29iy.o:(.data.rel.local.DW.ref._ZTIN11xercesc_3_212XMLExceptionE[DW.ref._ZTIN11xercesc_3_212XMLExceptionE]+0x0): undefined reference to `typeinfo for xercesc_3_2::XMLException'
collect2: error: ld returned 1 exit status
然而这些符号仍然存在。从主要对象来看:
$ objdump -t bogus.o | grep fgXerces
...
0000000000000000 *UND* 0000000000000000 _ZN11xercesc_3_26XMLUni22fgXercescDefaultLocaleE
...
xerces 库是:
$ objdump -t /usr/local/lib/libxerces-c.so| grep fgXerces
...
00000000002e0af2 g O .rodata 0000000000000006 _ZN11xercesc_3_26XMLUni22fgXercescDefaultLocaleE
...
所以,看来对象中的乱码名称与库中的名称相匹配。我无法弄清楚这一点。它在直接 Fedora 38 上工作得很好,但在运行 Ubuntu 20.04 的 WSL2 上却不行。
如有任何帮助,我们将不胜感激。
弄清楚了。显然,文件的顺序很重要,因此通过更改构建:
$ g++ -L/usr/local/lib -lxerces-c bogus.cpp -o bogus
到
$ g++ bogus.cpp -L/usr/local/lib -lxerces-c -o bogus
解决了问题。我仍然想评论一下为什么会这样。