对' icu_56::UnicodeString::UnicodeString(带符号的char,无符号的短const*, int)的未定义引用

时间:2021-07-08 05:38:05

I am running ubuntu, and I can build ICU

我正在运行ubuntu,我可以构建ICU

I have included:

我有包括:

#include <unistr.h>
using namespace icu;

This is my build method for ICU:

这是我构建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

编辑:这是构建项目时IDE的输出

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 warnings

3 个解决方案

#1


2  

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")?

我注意到,您的g+行没有指向/usr/local/lib/ libicuucu。a你说你安装了icu。它显然是针对header编译的,但是静态库是否存在于您正在使用的路径中(“/home/user/myProject/icu/ libicuuca .a”)?

#2


2  

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.

接下来,将测试程序修改为#include ,在任何事情之前,例如。

main.cpp

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.

它将编译并链接到libicuuca。

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.

如果您希望确保像unicode/uconfig这样的样板文件头,您可以。h和unicode /平台。h通过使用一个预包含头,被编译器自动包含在任何东西之前,例如。

icu_preinc.h

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:

您将其传递给GCC或clang,并提供以下选项:

-include /path/to/icu_preinc.h

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

如果使用基于标记的构建系统,可以将此选项放入CPPFLAGS中。

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>

对于上面的玩具程序,只需在命令行上定义u_disable_renamed =1就足够了,不包括

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

#3


1  

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

我认为问题出在g+语法上:

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:

您说的是使用object file main构建myProject。对象文件libicuuca。但是,后者不是对象文件,而是静态库。我认为您应该将g+行修改为:

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

l /home/user/myProject/icu/告诉链接器在/home/ user/myproject/icu/文件夹中查找库,-licuuc告诉它链接到一个名为libicuuc的库。或libicuuc.so

#1


2  

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")?

我注意到,您的g+行没有指向/usr/local/lib/ libicuucu。a你说你安装了icu。它显然是针对header编译的,但是静态库是否存在于您正在使用的路径中(“/home/user/myProject/icu/ libicuuca .a”)?

#2


2  

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.

接下来,将测试程序修改为#include ,在任何事情之前,例如。

main.cpp

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.

它将编译并链接到libicuuca。

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.

如果您希望确保像unicode/uconfig这样的样板文件头,您可以。h和unicode /平台。h通过使用一个预包含头,被编译器自动包含在任何东西之前,例如。

icu_preinc.h

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:

您将其传递给GCC或clang,并提供以下选项:

-include /path/to/icu_preinc.h

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

如果使用基于标记的构建系统,可以将此选项放入CPPFLAGS中。

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>

对于上面的玩具程序,只需在命令行上定义u_disable_renamed =1就足够了,不包括

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

#3


1  

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

我认为问题出在g+语法上:

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:

您说的是使用object file main构建myProject。对象文件libicuuca。但是,后者不是对象文件,而是静态库。我认为您应该将g+行修改为:

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

l /home/user/myProject/icu/告诉链接器在/home/ user/myproject/icu/文件夹中查找库,-licuuc告诉它链接到一个名为libicuuc的库。或libicuuc.so