Estoy ejecutando ubuntu y puedo construir ICU
He incluido:
#include <unistr.h> using namespace icu;Este es mi método de compilación para 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 installluego enlazo a
/usr/local/lib/libicuuc.ay tratar de compilar
icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);pero sale el error
undefined reference to `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)'Encontré otra publicación aquí en SO con respecto al mismo problema, pero cuando sigo los pasos proporcionados, no soluciona mi problema y puede ser una versión diferente.
EDITAR: Esta es la salida del IDE al construir el proyecto
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 "/home/user/myProject/myProject/bin/Debug/myProject" "/home/user/myProject/myProject/bin/Debug/main.o" "/home/user/myProject/icu/libicuuc.a" /home/user/myProject/myProject/bin/Debug/main.o: In function `icuTest': /home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::StringPiece::StringPiece(char const*)' /home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::fromUTF8(icu_56::StringPiece const&)' /home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::~UnicodeString()' /home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::~UnicodeString()' collect2: error: ld returned 1 exit status Build complete -- 4 errors, 0 warnings ---------------------- Done ---------------------- Build: 4 errors, 0 warningsCuando corrías:
./runConfigureICU Linux --enable-static --disable-shared --disable-renaming¿Hiciste caso a la advertencia?:
*** 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 1Si no, entonces hazlo ahora.
A continuación, modifique su programa de prueba para #include <unicode/uconfig.h> antes que nada, por ejemplo
principal.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; } El compilará y vinculará contra libicuuc.a .
Si lo desea, puede asegurarse de que el compilador incluya automáticamente los encabezados repetitivos como unicode/uconfig.h y unicode/platform.h antes que cualquier otra cosa mediante el uso de un encabezado pre-incluido, por ejemplo
icu_preinc.h
// pre-include header for icu #include <unicode/uconfig.h> #include <unicode/platform.h>que pasas a GCC o clang con la opción:
-include /path/to/icu_preinc.h Puede poner esta opción en su CPPFLAGS si usa un sistema de compilación basado en make .
En el caso del programa de juguete anterior, basta con definir U_DISABLE_RENAMING=1 en la línea de comandos, sin incluir <unicode/uconfig.h>
g++ -DU_DISABLE_RENAMING=1 -o prog main.cpp -L/your/libicuuc/search/path -licuucNoté que su línea g ++ no apunta a /usr/local/lib/libicuuc.a donde dice que instaló icu. Obviamente, se está compilando contra los encabezados, pero ¿existe la biblioteca estática en la ruta que está utilizando ("/home/user/myProject/icu/libicuuc.a")?
Creo que el problema está en la sintaxis de g++:
g++ -o "/home/user/myProject/myProject/bin/Debug/myProject" "/home/user/myProject/myProject/bin/Debug/main.o" "/home/user/myProject/icu/libicuuc.a"Está diciendo que construya myProject usando el archivo de objeto main.o y el archivo de objeto libicuuc.a. Sin embargo, este último no es un archivo de objeto, es una biblioteca estática. Creo que deberías modificar la línea g ++ a:
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/ le dice al enlazador que busque bibliotecas en la carpeta /home/user/myProject/icu/ y -licuuc le dice que vincule una biblioteca llamada libicuuc.a o libicuuc.so