You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下编译含icu::UnicodeString的C++文件遇ld链接错误

ICU C++ API 链接错误问题解决

问题场景

尝试使用ICU的icu::UnicodeString处理Unicode字符串,编写测试代码demo.cpp:

#include <unicode/unistr.h>
#include <unicode/utypes.h>
#include <unicode/ustream.h>

#include <iostream>

using namespace std;

int main(){
    icu::UnicodeString str("akeywords", 9, icu::UnicodeString::kInvariant);

    cout << str << endl;
}

使用构造函数icu::UnicodeString::UnicodeString(const char * src, int32_t textLength, enum EInvariant inv)初始化对象后,执行编译命令:

g++ demo.cpp -o demo.exe -I"D:\ICU\include" -L"D:\ICU\lib64" -licuin -licuuc -licuio

运行编译命令后出现ld链接错误,提示多个icu_74相关符号未定义。

环境信息

  • 操作系统:Windows 10
  • 编译器:g++ 13.2.0
  • ICU版本:74

ICU配置

  • 安装方式:下载MSVC编译的ICU压缩包解压
  • 安装路径:D:\ICU
  • 目录包含bin、lib64、include等文件夹

尝试操作

添加编译选项-licuio,问题未解决。

补充说明

此前成功编译过使用ICU纯C API(UCharsetDetector)的示例,编译命令为:

g++ demo.cpp -o demo.exe -I"D:\ICU\include" -L"D:\ICU\lib64" -licuin -licuuc

程序可正常运行,所有命令在msys2中执行,环境变量配置无误。

解决方案

问题根源是g++编译时链接了MSVC编译的ICU库,C API因具备可移植性未报错。需使用Mingw64工具链重新编译ICU库,问题已解决。

内容的提问来源于stack exchange,提问作者Aljen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 21:12:32