需要帮助来编译并运行C++带有ICU4C的源文件
操作系统: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”。
我做了什么:
- 下载
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 。
- 我的 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;
}
- 编译我的代码
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
- 运行
执行 ./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".
What I did:
- 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.
- 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;
}
- 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
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了你的代码,效果很好。
但是您正在构建应用程序的共享版本,这使得您的 .exe 文件依赖于 .dll 文件,而当您运行 .exe 时很可能找不到这些文件。
有几种方法可以解决这个问题:(
PATH
环境中变量(例如在命令中提示:SET PATH=C:\Program Files\icu4c-70_1-Win64-MSVC2019\bin64;%PATH%
)在运行a.exe之前警告:确保不要混合 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:
PATH
environment variable (e.g. in Command Prompt:SET PATH=C:\Program Files\icu4c-70_1-Win64-MSVC2019\bin64;%PATH%
) before running a.exeWarning: Make sure not to mix 32-bit and 64-bit .exe and .dll files.
我花了一些时间在这个问题上。这是答案:执行时使用错误的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 byICUIO70.dll
when I execute my program. But the MSVC version library doesn't provide it.