Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Migrating from QMake to CMake UNICODE definition issue
Forum Updated to NodeBB v4.3 + New Features

Migrating from QMake to CMake UNICODE definition issue

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 217 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex.olha
    wrote 17 days ago last edited by
    #1

    Hello everyone!
    I have the following problem: I cannot turn off UNICODE definition when using CMake to build my library.
    Library was build successfully when I used QMake with

    DEFINES -= UNICODE
    

    I switched to CMake and added the line to turn off unicode:

    remove_definitions(-DUNICODE -D_UNICODE)
    

    But I had no success and I still have unicode flags in arguments:

    C:\Qt\Tools\mingw1120_64\bin\g++.exe -DCLIENTCORELIB_LIBRARY -DClientCoreLib_EXPORTS -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DQT_NETWORK_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_MBCS -D_UNICODE -D_WIN64
    

    and errors in compile output.
    Could you guys please give me advise or solution to deal with this issue?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote 17 days ago last edited by JoeCFD 6 May 2025, 16:14
      #2

      When using remove_definitions(-DUNICODE -D_UNICODE) in CMake, it only removes definitions that were previously added by add_definitions or similar commands earlier in the same CMakeLists.txt file or included files. However, if UNICODE or _UNICODE is being defined elsewhere (e.g., by a parent project, a toolchain, or a system-level configuration), remove_definitions may not work as expected because it doesn't affect definitions set outside of CMake's explicit add_definitions.

      Can you try:
      add_compile_options(-UUNICODE -U_UNICODE)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote 17 days ago last edited by
        #3

        -DUNICODE for sure comes from Qt as it was compiled with this switch.
        Fix your header to not rely on this.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply 17 days ago
        0
        • C Christian Ehrlicher
          17 days ago

          -DUNICODE for sure comes from Qt as it was compiled with this switch.
          Fix your header to not rely on this.

          A Offline
          A Offline
          alex.olha
          wrote 17 days ago last edited by
          #4

          @JoeCFD Thanks a lot, your solution works!
          @Christian-Ehrlicher thank you too!

          Problem solved.

          1 Reply Last reply
          0
          • A alex.olha has marked this topic as solved 17 days ago
          • A alex.olha has marked this topic as solved 17 days ago

          3/4

          5 Jun 2025, 16:56

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved