Home Ask Login Register

Developers Planet

Your answer is one click away!

Chris February 2016

undefined reference to `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)'

I am running ubuntu, and I can build ICU

I have included:

#include <unistr.h>
using namespace icu;

This is my build method for ICU:

CPPFLAGS="-DU_USING_ICU_NAMESPACE=0" 
CPPFLAGS="-DU_CHARSET_IS_UTF8=1"

export CFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_STATIC_IMPLEMENTATION"
export CXXFLAGS="-DU_USING_ICU_NAMESPACE=0 -std=gnu++0x -DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_HAVE_CHAR16_T=1 -DUCHAR_TYPE=char16_t -Wall --std=c++0x -DU_STATIC_IMPLEMENTATION"
export CPPFLAGS="-DU_USING_ICU_NAMESPACE=0 -DU_CHARSET_IS_UTF8=1 -DU_STATIC_IMPLEMENTATION"
export LDFLAGS="-std=gnu++0x"

./runConfigureICU Linux --enable-static --disable-shared --disable-renaming

make check 
sudo make install

I then link to

/usr/local/lib/libicuuc.a

and try to compile

icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);

but get the error

undefined reference to `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)'

I found another post here on SO regarding the same problem, but when I follow the steps provided it does not fix my problem and may be a different version.

EDIT: This is the output from the IDE upon building the project

Cleaning Solution: myProject (Debug)

Cleaning: myProject (Debug)
Removing output files...
Clean complete

Building Solution: myProject (Debug)

Building: myProject (Debug)
Performing main compilation...

Precompiling headers

    Compiling source to object files
    g++  -MMD "/home/user/myProject/myProject/main.cpp" -g -O0 -std=c++11 -DDEBUG -I"/home/user/myProject/myProject/include" -I"/home/user/myProject/icu/unicode" -I"/home/user/myProject/myProject/.prec/Debug"  -c -o "/home/user/myProject/myProject/bin/Debug/main.o"

    Generating binary "myProject" from object files
    g++ -o "/ho        

Answers


MasterOfEntropy February 2016

I notice that your g++ line is not pointing to /usr/local/lib/libicuuc.a where you say you installed icu. It obviously is compiling against the headers OK, but does the static library exist in the path you are using ("/home/user/myProject/icu/libicuuc.a")?


Jakub Zaverka February 2016

I think the problem is in the g++ syntax:

g++ -o "/home/user/myProject/myProject/bin/Debug/myProject" "/home/user/myProject/myProject/bin/Debug/main.o" "/home/user/myProject/icu/libicuuc.a" 

You are saying to build myProject using object file main.o and object file libicuuc.a. However, the latter is not an object file, it is a static library. I think you should modify the g++ line to:

g++ /home/user/myProject/myProject/bin/Debug/main.o -L/home/user/myProject/icu/ -licuuc -o /home/user/myProject/myProject/bin/Debug/myProject

-L/home/user/myProject/icu/ tell the linker to look for libraries in /home/user/myProject/icu/ folder and -licuuc tells it o link a library named libicuuc.a or libicuuc.so


Mike Kinghan February 2016

When you ran:

./runConfigureICU Linux --enable-static --disable-shared --disable-renaming

did you heed the warning?:

*** WARNING: You must set the following flags before code compiled against this ICU will function properly:

    -DU_DISABLE_RENAMING=1

The recommended way to do this is to prepend the following lines to source/common/unicode/uconfig.h or #include them near the top of that file.

 /* -DU_DISABLE_RENAMING=1 */
#define U_DISABLE_RENAMING 1

If not, then do so now.

Next, modify your test program to #include <unicode/uconfig.h> before anything else, e.g.

main.cpp

#include <unicode/uconfig.h>
#include <unicode/platform.h>
#include <unicode/unistr.h>

int main()
{
    icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);
    (void)s1;
    return 0;
}

The it will compile and link against libicuuc.a.

You can if you wish ensure that boilerplate headers like unicode/uconfig.h and unicode/platform.h are automatically included by the the compiler before anything else by making use of a pre-include header, e.g.

icu_preinc.h

// pre-include header for icu
#include <unicode/uconfig.h>
#include <unicode/platform.h>

which you pass to GCC or clang with the option:

-include /path/to/icu_preinc.h

You can put this option in your CPPFLAGS if you use a make-based build system.

In the case of the toy program above it is enough just to define U_DISABLE_RENAMING=1 on the commandline, without including <unicode/uconfig.h>

g++ -DU_DISABLE_RENAMING=1 -o prog main.cpp -L/your/libicuuc/search/path -licuuc

Post Status

Asked in February 2016
Viewed 1,978 times
Voted 6
Answered 3 times

Search




Leave an answer


Quote of the day: live life