Compiling-ICU-with-MinGW: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Update PATH variable, is should be icu/dist/bin)
(Add some notes on how to use pre-compiled mingw icu libs)
 
Line 2: Line 2:
[[Category:Windows]]
[[Category:Windows]]
[[Category:Qt5]]
[[Category:Qt5]]
[[Category:Qt6]]
[[Category:ICU]]
[[Category:ICU]]


== Compiling ICU with MinGW (for adding Unicode support) ==
==Compiling ICU with MinGW (for adding Unicode support)==


Qt 5 / QtWebkit requires ICU, which MinGW distributions do not ship.
If you need more text codec than the basic ones with Qt/MinGW you have to compile Qt (QtBase) by yourself. See also https://bugreports.qt.io/browse/QTBUG-140865


== Pre-built packages ==
==Pre-built packages==


The [http://site.icu-project.org/download ICU Project site] provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2010 runtime being installed.
The [http://site.icu-project.org/download ICU Project site] provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2010 runtime being installed.


[http://download.qt.io/development_releases/prebuilt/icu/prebuilt/mingw/ download.qt.io] also hosts packages for the MinGW toolchains Qt ships.
[http://download.qt.io/development_releases/prebuilt/icu/prebuilt/mingw/ download.qt.io] also hosts packages for the MinGW toolchains Qt ships, but only for old versions. A recent pre-compiled version can be downloaded from https://packages.msys2.org/packages/mingw-w64-x86_64-icu - it only depends on msvcrt.dll and mingw runtime libs.


Inside MSYS2 shell, a pre-built ICU can be obtained. MSYS2 also contains pre-built dynamic Qt & QtCreator (and static Qt) with ICU & OpenSSL support.
==Compiling on your own==


== Compiling on your own ==
===Requirements===


=== Requirements ===
*Either use MSYS or use [[MSYS2]].  
 
**MSYS shell command prompt (an sh shell + some UNIX tools, get it from http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download?use_mirror=garr. It's also an (optional) part of mingw.org installer.)
* Either use MSYS or use [[MSYS2]].  
**[[MSYS2]] shell command prompt, (similar to MSYS), it can be obtained from https://msys2.github.io/
** MSYS shell command prompt (an sh shell + some UNIX tools, get it from http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download?use_mirror=garr. It's also an (optional) part of mingw.org installer.)
** [[MSYS2]] shell command prompt, (similar to MSYS), it can be obtained from https://msys2.github.io/  
* Working MinGW, or MinGW-w64 toolchain.
* Working MinGW, or MinGW-w64 toolchain.
** Load MinGW or MinGW-w64 toolchains.
** Load MinGW or MinGW-w64 toolchains.
** NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, targeted for same platform/OS. If you are using MinGW-w64 toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for building main project & all of its sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for building all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for building all sub-components & main project, use same MinGW-builds toolchains.
**NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, targeted for same platform/OS. If you are using MinGW-w64 toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for building main project & all of its sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for building all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for building all sub-components & main project, use same MinGW-builds toolchains.


=== How to build ===
===How to build===


* Download latest ICU4C source code from http://site.icu-project.org/download (e.g. icu4c-52_1-src.zip), unzip
*Download latest ICU4C source code from http://site.icu-project.org/download (e.g. icu4c-52_1-src.zip), unzip
* Either start MSYS-shell, or start MSYS2-shell:
*Either start MSYS-shell, or start MSYS2-shell:
** Start a MSYS shell command prompt (C:.0\msys.bat)
**Start a MSYS shell command prompt (C:.0\msys.bat)
** Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
**Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
*** See in [[MSYS2]] page, how to prepare MSYS2-shell with build/compile related tools & dependencies & toolchains  
***See in [[MSYS2]] page, how to prepare MSYS2-shell with build/compile related tools & dependencies & toolchains


* Inside MSYS or MSYS2 shell, run/execute below command:
* Inside MSYS or MSYS2 shell, run/execute below command:
Line 40: Line 39:
</code>
</code>


* Check that gcc is in PATH, otherwise add it:
*Check that gcc is in PATH, otherwise add it:
** If using MSYS shell, and if MinGW (32bit) is installed inside /c/mingw32 directory, then execute this:
**If using MSYS shell, and if MinGW (32bit) is installed inside /c/mingw32 directory, then execute this:
<code>
<code>
$ export PATH="/c/mingw32/bin:$PATH"
$ export PATH="/c/mingw32/bin:$PATH"
</code>
</code>  
** If using MSYS2 shell, execute this, if you are building for 32bit:
**If using MSYS2 shell, execute this, if you are building for 32bit:
<code>
<code>
$ export PATH="/c/msys2/mingw32/bin:$PATH"
$ export PATH="/c/msys2/mingw32/bin:$PATH"
</code>
</code>
** If using MSYS2 shell, execute this, if you are building for 64bit:
**If using MSYS2 shell, execute this, if you are building for 64bit:
<code>
<code>
$ export PATH="/c/msys2/mingw64/bin:$PATH"
$ export PATH="/c/msys2/mingw64/bin:$PATH"
</code>
</code>


* Run configure && build:
*Run configure && build:
<code>
<code>
$ ./runConfigureICU MinGW prefix=$PWD/../dist
$ ./runConfigureICU MinGW prefix=$PWD/../dist
Line 61: Line 60:
This will generate a release shared build that you can use in both a debug and release build of Qt.
This will generate a release shared build that you can use in both a debug and release build of Qt.


* To link ICU statically (e.g. for a static release build of Qt), you have to append ‘—enable-static —disable-shared’ :
*To link ICU statically (e.g. for a static release build of Qt), you have to append ‘—enable-static —disable-shared’ :
<code>
<code>
$ ./runConfigureICU MinGW —prefix=$PWD/../dist —enable-static —disable-shared
$ ./runConfigureICU MinGW —prefix=$PWD/../dist —enable-static —disable-shared
</code>
</code>  


* To link ICU statically and build it in debug mode (e.g. for a static debug build of Qt), you have to prepend ‘—enable-debug —disable-release’ to the arguments:
*To link ICU statically and build it in debug mode (e.g. for a static debug build of Qt), you have to prepend ‘—enable-debug —disable-release’ to the arguments:
<code>
<code>
$ ./runConfigureICU —enable-debug —disable-release MinGW —prefix=$PWD/../dist —enable-static —disable-shared
$ ./runConfigureICU —enable-debug —disable-release MinGW —prefix=$PWD/../dist —enable-static —disable-shared
</code>
</code>


* Finally, run make && make install
*Finally, run make && make install
<code>
<code>
$ make && make install
$ make && make install
</code>
</code>


== Using it ==
==Using it==


* Add the include, lib folders to your compilation environment, e.g. for cmd.exe (Cmd-shell) :
*Add the include, lib folders to your compilation environment, e.g. for cmd.exe (Cmd-shell) :
<code>
<code>
C:> set PATH=%PATH%;C:\icu\dist\bin
C:> set PATH=%PATH%;C:\icu\dist\bin
Line 85: Line 84:
</code>
</code>


* Add the include, lib folders to your compilation environment, e.g. for MSYS2-shell (or for MSYS-shell) :
*Add the include, lib folders to your compilation environment, e.g. for MSYS2-shell (or for MSYS-shell) :
<code>
<code>
$ export PATH="$PATH:/c/icu/dist/bin"
$ export PATH="$PATH:/c/icu/dist/bin"

Latest revision as of 18:32, 6 October 2025


Compiling ICU with MinGW (for adding Unicode support)

If you need more text codec than the basic ones with Qt/MinGW you have to compile Qt (QtBase) by yourself. See also https://bugreports.qt.io/browse/QTBUG-140865

Pre-built packages

The ICU Project site provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2010 runtime being installed.

download.qt.io also hosts packages for the MinGW toolchains Qt ships, but only for old versions. A recent pre-compiled version can be downloaded from https://packages.msys2.org/packages/mingw-w64-x86_64-icu - it only depends on msvcrt.dll and mingw runtime libs.

Compiling on your own

Requirements

  • Either use MSYS or use MSYS2.
  • Working MinGW, or MinGW-w64 toolchain.
    • Load MinGW or MinGW-w64 toolchains.
    • NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, targeted for same platform/OS. If you are using MinGW-w64 toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for building main project & all of its sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for building all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for building all sub-components & main project, use same MinGW-builds toolchains.

How to build

  • Download latest ICU4C source code from http://site.icu-project.org/download (e.g. icu4c-52_1-src.zip), unzip
  • Either start MSYS-shell, or start MSYS2-shell:
    • Start a MSYS shell command prompt (C:.0\msys.bat)
    • Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
      • See in MSYS2 page, how to prepare MSYS2-shell with build/compile related tools & dependencies & toolchains
  • Inside MSYS or MSYS2 shell, run/execute below command:
$ cd icu/source
  • Check that gcc is in PATH, otherwise add it:
    • If using MSYS shell, and if MinGW (32bit) is installed inside /c/mingw32 directory, then execute this:
$ export PATH="/c/mingw32/bin:$PATH"
    • If using MSYS2 shell, execute this, if you are building for 32bit:
$ export PATH="/c/msys2/mingw32/bin:$PATH"
    • If using MSYS2 shell, execute this, if you are building for 64bit:
$ export PATH="/c/msys2/mingw64/bin:$PATH"
  • Run configure && build:
$ ./runConfigureICU MinGW prefix=$PWD/../dist

This will generate a release shared build that you can use in both a debug and release build of Qt.

  • To link ICU statically (e.g. for a static release build of Qt), you have to append ‘—enable-static —disable-shared’ :
$ ./runConfigureICU MinGW prefix=$PWD/../dist enable-static disable-shared
  • To link ICU statically and build it in debug mode (e.g. for a static debug build of Qt), you have to prepend ‘—enable-debug —disable-release’ to the arguments:
$ ./runConfigureICU enable-debug disable-release MinGW prefix=$PWD/../dist enable-static disable-shared
  • Finally, run make && make install
$ make && make install

Using it

  • Add the include, lib folders to your compilation environment, e.g. for cmd.exe (Cmd-shell) :
C:> set PATH=%PATH%;C:\icu\dist\bin
C:> set INCLUDE=%INCLUDE%;C:\icu\dist\include
C:> set LIB=%LIB%;C:\icu\dist\lib
  • Add the include, lib folders to your compilation environment, e.g. for MSYS2-shell (or for MSYS-shell) :
$ export PATH="$PATH:/c/icu/dist/bin"
$ export INCLUDE="$INCLUDE:/c/icu/dist/include"
$ export LIB="$LIB:/c/icu/dist/lib"

When you now run Qt’s configure.exe ICU should be detected, and Qt links against the libraries.