Conditional compile of feature windows_by_handle under Linux?

I put #![feature(windows_by_handle)] at the top of the main.rs.
But my app is supposed to run on Linux and Windows.

#[cfg(target_os = "windows")]
#![feature(windows_by_handle)]

It will not gonna work. The aove syntax is not supported.

If I just compile directly on a Linux machine, it will report the error:

$ cargo +nightly b
   Compiling server-app v0.1.0 (/src/server-app)
error[E0635]: unknown feature `windows_by_handle`
 --> server/src/main.rs:1:12
  |
1 | #![feature(windows_by_handle)]
  |            ^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0635`.
error: could not compile `server-app` (bin "server-app") due to previous error

I believe you want is

#![cfg_attr(target_os = "windows", feature(windows_by_handle))]

Which conditionally applies another attribute

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.