简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM