Windows.h 和 clang (LLVM)

发布于 2024-09-12 14:01:18 字数 2682 浏览 5 评论 0原文

我正在尝试使用 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...

I'm trying to compile a little project that includes windows.h using the clang compiler. Unfortunately, clang produces some errors I'm not able to resolve. What's causing these errors? Does clang not support all required features, am I missing something?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2024-09-19 14:01:18

您可能需要定义 UNREFERENCED_PARAMETER 宏的 clang 兼容版本。这样的东西应该可以帮助您: https://web.archive.org/web/20130425151054/http://sourcefrog.n​​et/weblog/software/languages/C/unused.html

另外,似乎是 LONGLONG 类型对于 clang 被定义为 double,并且您不能对浮点数进行二进制算术(与、或、非等)。您需要确保将其类型定义为正确的整数类型。

根据 windows.h、winbase.h 和 winnt.h 的结构,您也许能够制作自己的包装器,以获取正确的定义来完成此传递。否则,尝试找到 Windows.h 的 gcc 兼容版本,并使用它。 Clang 应该兼容它。

祝你好运!

You probably need to define a clang-compatible version of the UNREFERENCED_PARAMETER macro. Something like this should help you on the way: https://web.archive.org/web/20130425151054/http://sourcefrog.net/weblog/software/languages/C/unused.html

Also, it seems the type LONGLONG is defined as double for clang, and you can't do binary arithmetic (and, or, not etc) on floats. You need to make sure this is typedefed as a proper integer type.

Depending a bit on how windows.h, winbase.h and winnt.h is structured you may be able to make your own wrapper that gets the right defines in place to make this pass. Otherwise, try to find a gcc-compatible version of windows.h, and use that. Clang should be compatible with it.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文