Windows.h和clang(LLVM)

时间:2010-08-04 06:26:40

标签: c llvm clang

我正在尝试使用clang编译器编译一个包含windows.h的小项目。不幸的是,clang会产生一些我无法解决的错误。是什么导致了这些错误? clang不支持所有必需的功能,我错过了什么吗?

In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:155:
In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ef.h:177:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h(12857) :  warning:

  expression result unused [-Wunused-value]
UNREFERENCED_PARAMETER(CallbackEnviron);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h:12857:28: note: in
stantiated from:
UNREFERENCED_PARAMETER(CallbackEnviron);
                       ^~~~~~~~~~~~~~~

In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:156:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2326) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old & Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2327) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2325) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2344) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old | Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2345) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2343) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2362) :  error:

  invalid operands to binary expression ('LONGLONG' (aka 'double') and
  'LONGLONG')
                                      Old ^ Value,
                                      ~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2363) :  error:

  expected ')'
                                      Old) != Old);
                                           ^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2361) :  note:
  to match this '('
} while (InterlockedCompareExchange64(Destination,
        ^

...and a lot more...

1 个答案:

答案 0 :(得分:3)

您可能需要定义一个与clare兼容的UNREFERENCED_PARAMETER宏版本。这样的事情可以帮助你:https://web.archive.org/web/20130425151054/http://sourcefrog.net/weblog/software/languages/C/unused.html

此外,似乎LONGLONG类型被定义为clang的double,并且你不能对浮点数进行二进制算术运算(和,或者不是等)。您需要确保将typedefed设置为正确的整数类型。

根据windows.h,winbase.h和winnt.h的结构,您可以制作自己的包装器,以获得正确的定义以进行此传递。否则,尝试找到与gcc兼容的windows.h版本,并使用它。 Clang应与之兼容。

祝你好运!