icu项目与MinGW和Netbeans -未定义的参考



我按照如下所示配置了MinGW和ICU-Project源代码。

我试着编译这段代码:

#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <timezone.h>
#include <inttypes.h>
#include <string>
#include <unistr.h>
using namespace std;
int main(int argc, char** argv) {
    UnicodeString id;
    TimeZone* tz =  TimeZone::createTimeZone(id);   
    int32_t raw,dst;
    int64_t when = 1367836520*U_MILLIS_PER_SECOND;
    UErrorCode ec = U_ZERO_ERROR;
    tz->getOffset((UDate)when,FALSE,raw,dst,ec);
    cout<<raw<<endl;
    cout<<dst<<endl;   
}

,我得到以下编译错误:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/Florian/Documents/NetBeansProjects/CppApplication_1'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_1.exe
make[2]: Entering directory `/c/Users/Florian/Documents/NetBeansProjects/CppApplication_1'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++    -c -g -I../../../../../MinGW/msys/1.0/local/include/unicode -I../../../../../MinGW/msys/1.0/local/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
main.cpp: In Funktion �int main(int, char**)�:
main.cpp:27:31: Warnung: Ganzzahl�berlauf in Ausdruck [-Woverflow]
mkdir -p dist/Debug/MinGW-Windows
g++     -o dist/Debug/MinGW-Windows/cppapplication_1 build/Debug/MinGW-Windows/main.o 
build/Debug/MinGW-Windows/main.o: In function `main':
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/main.cpp:24: undefined reference to `icu_51::TimeZone::createTimeZone(icu_51::UnicodeString const&)'
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/main.cpp:31: undefined reference to `icu_51::UnicodeString::~UnicodeString()'
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/main.cpp:31: undefined reference to `icu_51::UnicodeString::~UnicodeString()'
build/Debug/MinGW-Windows/main.o: In function `ZN6icu_517UObjectC2Ev':
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/../../../../../MinGW/msys/1.0/local/include/unicode/uobject.h:221: undefined reference to `vtable for icu_51::UObject'
build/Debug/MinGW-Windows/main.o: In function `ZN6icu_5111ReplaceableC2Ev':
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/../../../../../MinGW/msys/1.0/local/include/unicode/rep.h:240: undefined reference to `vtable for icu_51::Replaceable'
build/Debug/MinGW-Windows/main.o: In function `ZN6icu_5113UnicodeStringC1Ev':
C:UsersFlorianDocumentsNetBeansProjectsCppApplication_1/../../../../../MinGW/msys/1.0/local/include/unicode/unistr.h:3615: undefined reference to `vtable for icu_51::UnicodeString'
collect2.exe: Fehler: ld gab 1 als Ende-Status zur�ck
make[2]: *** [dist/Debug/MinGW-Windows/cppapplication_1.exe] Error 1
make[2]: Leaving directory `/c/Users/Florian/Documents/NetBeansProjects/CppApplication_1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/Users/Florian/Documents/NetBeansProjects/CppApplication_1'
make: *** [.build-impl] Error 2

你知道这些错误是什么意思吗?

main.cpp:31: undefined reference to `icu_51::UnicodeString::~UnicodeString()'

这些错误在头文件中,我想从icu项目中使用,发生了什么?

我也遇到了同样的问题。

main.cpp:31:未定义引用' icu_51::UnicodeString::~UnicodeString()'

上面的错误表示链接器找不到UnicodeString析构函数的定义。

您必须在项目中链接相应的库:icuin(由于undefined reference to icu_51::TimeZone::createTimeZone), icuuc(由于undefined reference to icu_51::UnicodeString::~UnicodeString())。

我还得链接icudt。

在path/to/icu/lib目录中查找适当的库名。例如,对于静态icu,它们是:sicuuc, sicuin, sicust等。

错误原因:

main.cpp:31: undefined reference to `icu_51::UnicodeString::~UnicodeString()'

表示缺少命名方法的定义。例如,下面是一个抛出这种错误的基本c++程序:

#include <iostream>
using namespace std;
class utilities{
public:
  void myfunction();
};
int main() {
    utilities util;
    util.myfunction();
    return 0;
}

抛出错误:

main.cpp:11: undefined reference to `utilities::myfunction()'

注意utilities::myfunction从来没有定义过。要解决这个问题,必须包含缺失函数的定义。这样的:

#include <iostream>
using namespace std;
class utilities{
public:
  void myfunction();
};
int main() {
    utilities util;
    util.myfunction();
    return 0;
}
void utilities::myfunction(){   
}

相关内容

  • 没有找到相关文章

最新更新