需要帮助来编译并运行C++带有ICU4C的源文件

发布于 2025-01-20 06:08:49 字数 1684 浏览 0 评论 0原文

操作系统:Windows 10

编译器:g++.exe(MinGW-W64 x86_64-posix-seh,由 Brecht Sanders 构建)11.2.0

Shell:msys2

描述 bug:

我想在 icu4c 中使用 class UnicodeString我的 C++ 代码。我下载了icu4c源代码并编译了它。我使用 icu4c 库编译了代码,但结果 .exe 文件无法成功执行。如果我在 msys2 中运行该 .exe 文件,它不会输出任何内容。如果我在 Windows 文件资源管理器中双击该 .exe 文件,则会显示一个对话框,显示“xxx.exe - 找不到该条目。无法在动态链接库 xxx.exe 中找到程序入口点 xxxxx”。

输入图片此处描述

我做了什么:

  1. 下载icu4c-70_1-src.zip并按照此链接的步骤进行编译Compiling-ICU-with-MinGW
$ cd icu/source
$ CC=gcc CXX=g++  ./runConfigureICU MinGW prefix=$PWD/../dist
make && make install

当我运行 make install,它显示错误,例如:创建符号链接失败。 但目录中存在libicuuc.dll.a之类的文件。所以我想我已经成功编译了 icu4c 。

  1. 我的 C++ 源文件

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

#include <iostream>

using namespace std;
using namespace icu;

int main() {
    cout << "hello,world" << endl;

    UnicodeString s("你好,世界");
    cout << s << endl;
}

  1. 编译我的代码
g++ main.cpp -I/c/Users/stskyblade/source/icu4c-70_1-src/icu/dist/include -L/c/Users/stskyblade/source/icu4c-70_1-src/icu/dist/lib -licuuc -licuio
  1. 运行

执行 ./a.exe 或双击文件资源管理器中的图标

我期望什么

我的程序可以用英语和英语输出 hello,world中文.

OS: Windows 10

Compiler: g++.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0

Shell: msys2

Describe the bug:

I want to use class UnicodeString in icu4c in my c++ code. I downloaded the icu4c source code and compiled it. I compiled my code with icu4c library, but the result .exe file can't be executed successfully. If I run that .exe file in msys2, it outputs nothing. If I double clicked that .exe file in windows file explorer, it shows a dialog saying "xxx.exe - Can't find the entry. Unable to locate program entry point xxxxx in the dynamic link library xxx.exe".

enter image description here

What I did:

  1. Download icu4c-70_1-src.zip and compile it following steps of this link Compiling-ICU-with-MinGW
$ cd icu/source
$ CC=gcc CXX=g++  ./runConfigureICU MinGW prefix=$PWD/../dist
make && make install

When I run make install, it displays error like: create symbol link failed.
But there exists files like libicuuc.dll.a in the directory. So I supposed I have compiled icu4c successfully.

  1. my c++ source file

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

#include <iostream>

using namespace std;
using namespace icu;

int main() {
    cout << "hello,world" << endl;

    UnicodeString s("你好,世界");
    cout << s << endl;
}

  1. compile my code
g++ main.cpp -I/c/Users/stskyblade/source/icu4c-70_1-src/icu/dist/include -L/c/Users/stskyblade/source/icu4c-70_1-src/icu/dist/lib -licuuc -licuio
  1. run

Execute ./a.exe or double click the icon in file explorer

What I expect

My program can output hello,world both in English and in Chinese.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2025-01-27 06:08:49

我尝试了你的代码,效果很好。

但是您正在构建应用程序的共享版本,这使得您的 .exe 文件依赖于 .dll 文件,而当您运行 .exe 时很可能找不到这些文件。

有几种方法可以解决这个问题:(

  • 最简单、最快)将 a.exe 复制到您提取 icu4c-70_1-src.zip 的位置下的文件夹(.dll 文件所在的位置),然后从那里运行它
  • 复制所需的 .dll文件(或所有文件,如果您不知道哪些文件)到与 a.exe 相同的位置,然后再次尝试运行 a.exe
  • 将包含 .dll 文件的位置添加到 PATH 环境中变量(例如在命令中提示:SET PATH=C:\Program Files\icu4c-70_1-Win64-MSVC2019\bin64;%PATH%)在运行a.exe之前
  • 构建一个静态版本,将a.exe链接到静态库,但这可能还需要手动指定 icu 的依赖项及其依赖项等...

警告:确保不要混合 32 位和 64 位 .exe 和 .dll 文件。

I tried your code and it works fine.

But you're building a shared version of your application, which makes your .exe file depend on .dll files, which most likely can't be found when you run your .exe.

A few ways to get around that:

  • (simplest and quickest) copy a.exe to the folder under the location where you extracted icu4c-70_1-src.zip where the .dll files are located and run it from there
  • copy the required .dll files (or all of them if you don't know which ones) to the same location as a.exe and then try running a.exe again
  • add the location containing the .dll files to the PATH environment variable (e.g. in Command Prompt: SET PATH=C:\Program Files\icu4c-70_1-Win64-MSVC2019\bin64;%PATH%) before running a.exe
  • build a static version that links a.exe to static libraries, but this may also require icu's dependencies to be specified manually and their dependencies, etc...

Warning: Make sure not to mix 32-bit and 64-bit .exe and .dll files.

空气里的味道 2025-01-27 06:08:49

我花了一些时间在这个问题上。这是答案:执行时使用错误的DLL文件。

我的计算机中有两个版本的ICU4C DLL文件。

其中一些位于目录中c:\ program Files \ ICU4C-70_1-WIN64-MSVC2019 \ bin64,然后直接从ICU4C的GitHub Release Page下载它们。
它们是由Microsoft的编译器构建的。该目录在路径环境变量中。

另一个版本位于目录中c:\ users \ xxxx \ source \ icu4c-70_1-src \ icu \ icu \ dist \ bin。它们是由我自己建造的。此目录不在路径环境变量中。

我用第二版的库文件编译了程序。但是,当我执行程序时,系统使用第一个版本的DLL文件。就是这样。这两个库的版本不兼容。

符号_ZN6ICU_70LSERSORKNS_13UNICODESTRINGE是我使用Mingw版本库编译程序时的函数。当我执行程序时,该符号的输入点应由icuio70.dll提供。但是MSVC版本库无法提供。

I have spent some time on this problem. Here is the answer: This program used wrong dll files when be executed.

There are two versions of ICU4C dll files in my computer.

Some of them are located in directory C:\Program Files\icu4c-70_1-Win64-MSVC2019\bin64, and they are downloaded directly from github release page of ICU4C.
They are built with Microsoft's compiler. This directory is in the PATH environment variable.

Another version are located in directory C:\Users\xxxx\source\icu4c-70_1-src\icu\dist\bin. They are built with mingw-w64 GCC compiler on my own. And this directory is not in the PATH environment variable.

I compiled my program with library files of the second version. But the system use the first version dll files when I execute my program. That's it. These two versions of library is not compatible.

Symbol _ZN6icu_70lsERSoRKNS_13UnicodeStringE is a function called by my function when I compile my program with MinGW version library. The entry point of that symbol should be provided by ICUIO70.dll when I execute my program. But the MSVC version library doesn't provide it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文