How to undefine `__LP64__` in a CMake project?
16:26 20 Dec 2025

I am trying to get a legacy Windows project to compile (not link, not run) under Arch Linux.

To that very limited end I had good success to simply replace its Windows SDK 7.1a headers with those from wine.

Unfortunately these contain the following troublesome definitions:

#if !defined(__LP64__) && !defined(WINE_NO_LONG_TYPES) && !defined(WINE_UNIX_LIB)
typedef long            LONG,       *PLONG;
#else
typedef int             LONG,       *PLONG;
#endif
#if !defined(__LP64__) && !defined(WINE_NO_LONG_TYPES) && !defined(WINE_UNIX_LIB)
typedef long                                   *LPLONG;
typedef unsigned long   DWORD,      *PDWORD,   *LPDWORD;
#else
typedef int                                    *LPLONG;
typedef unsigned int    DWORD,      *PDWORD,   *LPDWORD;
#endif

and the #else branch is used as, CLion tells me:

predefined macro
__LP64__ 1

I tried a number of ways to get rid of it, but none of them has any effect and as per typical CMake behaviour, there is no diagnostics as to why it ignores my instructions:

  • remove_definitions(__LP64__) in CMakeLists.txt
  • set(CMAKE_SYSTEM_PROCESSOR i386) in CMakeLists.txt
  • set(CMAKE_TOOLCHAIN_FILE cmake/x86.cmake) in CMakeLists.txt and a corresponding toolchain file with the instruction above
  • "environment": {
      "CMAKE_SYSTEM_PROCESSOR": "i386",
      "CMAKE_TOOLCHAIN_FILE": "cmake/x86.cmake"
    },
    
    in a configuration preset in CMakePresets.json

As I have no aspiration (yet) to create something that actually runs, is there a convenient way to get rid of the __LP64__ macro for now, so I can start porting?

... For now I have simply deleted the "wrong" branch, but that is somewhat bothersome to automate and not forget to eventually revert.

cmake archlinux wine