linking error: undefined reference to icu_50::UnicodeString::UnicodeString()

谁说胖子不能爱 提交于 2019-12-10 17:16:41

问题


I am trying to compile my project where I've declared as class members some:

icu::UnicodeString label;
icu::UnicodeString tags;
icu::UnicodeString domain;
icu::UnicodeString data;

After having included (yes it is found)

#include <unicode/unistr.h>

In my CMakeLists.txt it searches, finds and links with: icuuc icudata (libicuuc, libicudata) as the output suggests prior to throwing the errors:

-o icarus -rdynamic -lPocoNet -lPocoUtil -lPocoXML -licuuc -licudata

I have built and installed from source icu4c 50.1.2, and installed it under /usr/local/* cmake finds the libraries properly, as my errors are from the linking phase:

undefined reference to icu_50::UnicodeString::UnicodeString()' undefined reference toicu_50::UnicodeString::~UnicodeString()'

I am using gcc-4.7.2 with -std=c++0x enabled on Debian Wheezy. The exact same code did compile with gcc-4.3.2 with the same flags on Debian Squeeze last night!

I cannot for the life of me, figure out what I am doing wrong! Please help!


回答1:


It appears this was my fault when building ICU4C. I am leaving a brief explanation as I have seen many google posts on this but no answers. If you read carefully the documentation when configuring icu, it states that you should do certain things:

1) Define using namespace to false:

 #   ifndef U_USING_ICU_NAMESPACE
-#       define U_USING_ICU_NAMESPACE 1
+        // Set to 0 to force namespace declarations in ICU usage.
+#       define U_USING_ICU_NAMESPACE 0

2) When building on linux, I went for a non-shared, static library:

runConfigureICU Linux --enable-static --disable-shared

3) This is the important part that caused my errors:

By default, ICU library entry point names have an ICU version suffix. Turn this off for a system-level installation, to enable upgrading ICU without breaking applications. For example:

runConfigureICU Linux --disable-renaming

The public header files from this configuration must be installed for applications to include and get the correct entry point names.

I did do that on Squeeze, but not on Wheezy, thus causing all the linkage errors on a system-wide installation. Lesson learned, hope it helps someone else.



来源:https://stackoverflow.com/questions/14875047/linking-error-undefined-reference-to-icu-50unicodestringunicodestring

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