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.
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.