How to debug linker errors? Getting undefined reference errors when statically linking ICU

纵然是瞬间 提交于 2019-12-22 10:46:58

问题


I've built the static libraries for ICU 49 and 50 but when linking with either one of them I still get 667 linker errors like the ones below. How can I approach debugging this and figuring out what the problem is? The ICU support list has offered no help at all.

clang++ -ccc-gcc-name g++ -Wl,-E -o velocity main.o city.o auto_lua.o
obj_builder.o index.o obj.o str.o db.o datetime.o msg_parser.o
task_scheduler.o gc.o global_settings.o transaction.o schema.o
skip_node.o util.o thread_context.o hashtable_base.o attr.o
page_pool.o result_buffer.o server_epoll.o logging.o test_server.o
test_main.o     -L../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -lc++
-lllalloc -lluajit -ldl -lm -lrt -lboost_system -lboost_filesystem
-licuuc -licui18n -licudata -lgtest
../lib/libicui18n.a(ucol.ao): In function `uprv_new_collIterate_50':
ucol.cpp:(.text.uprv_new_collIterate_50+0x37): undefined reference to
`icu_50::UMemory::operator new(unsigned long)'
ucol.cpp:(.text.uprv_new_collIterate_50+0xd2): undefined reference to
`icu_50::UMemory::operator delete(void*)'
../lib/libicui18n.a(ucol.ao): In function `uprv_delete_collIterate_50':
ucol.cpp:(.text.uprv_delete_collIterate_50+0x2f): undefined reference
to `icu_50::UMemory::operator delete(void*)'
../lib/libicui18n.a(ucol.ao): In function `initializeFCD(UErrorCode*)':
ucol.cpp:(.text._ZL13initializeFCDP10UErrorCode+0x2c): undefined
reference to `icu_50::Normalizer2Factory::getNFCImpl(UErrorCode&)'
../lib/libicui18n.a(ucol.ao): In function `ucol_initCollator_50':
ucol.cpp:(.text.ucol_initCollator_50+0x126): undefined reference to
`utrie_unserialize_50'
../lib/libicui18n.a(ucol.ao): In function `ucol_prv_getSpecialCE_50':
ucol.cpp:(.text.ucol_prv_getSpecialCE_50+0x9f6): undefined reference
to `u_charDigitValue_50'
ucol.cpp:(.text.ucol_prv_getSpecialCE_50+0xc1f): undefined reference
to `u_charDigitValue_50'

Running nm on the compiled static libraries I see this:

nm -A libicu* | grep u_charDigitValue_50
libicui18n.a:unum.ao:                 U u_charDigitValue_50
libicui18n.a:decimfmt.ao:                 U u_charDigitValue_50
libicui18n.a:dcfmtsym.ao:                 U u_charDigitValue_50
libicui18n.a:ucol.ao:                 U u_charDigitValue_50
libicui18n.a:regexcmp.ao:                 U u_charDigitValue_50
libicui18n.a:rematch.ao:                 U u_charDigitValue_50
libicui18n.a:uregex.ao:                 U u_charDigitValue_50
libicui18n.a:tzfmt.ao:                 U u_charDigitValue_50
libicuuc.a:uchar.ao:0000000000000000 T u_charDigitValue_50
libicuuc.a:rbbiscan.ao:                 U u_charDigitValue_50

Which leads me to believe (but I'm no expert) that the functions are actually defined in the static libs with the correct names (second line from the bottom, notice it matches the name of the missing symbol at the bottom of the pasted errors.)

I defined U_STATIC_IMPLEMENTATION=1 and I tried compiling both 49 and 50 under both clang and gcc. I'm on an ubuntu x64 system. When I make check after building the static libs, it passes all tests. I'm at a loss as to how to proceed. Any ideas I can try?


回答1:


If you're dealing with static libraries, it could be a link order problem.

Try calling the linker with the .a libs in reverse order of dependence.



来源:https://stackoverflow.com/questions/13253017/how-to-debug-linker-errors-getting-undefined-reference-errors-when-statically-l

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