Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

windef.h include via windows.h include causes issue with "near" and "far" names #130

Closed
nvibd opened this issue Mar 3, 2021 · 5 comments
Assignees
Labels

Comments

@nvibd
Copy link

nvibd commented Mar 3, 2021

In our application related to 3D geometry, we use near and far names. Recently, we started using libcu++ and more specifically <cuda/std/atomic>. However, this causes issues as there is an indirect inclusion of "windef.h", which #defines "near" and "far" to nothing.

There are some possible workarounds, including adding #undefs for "near" and "far" after every libcu++ include, or renaming all conflicting variables.

Still, it would be preferable if libcu++ would somehow avoid or prevent these extra macro definitions coming from "windows.h".

@nvibd
Copy link
Author

nvibd commented Mar 3, 2021

Here's a minimal example that causes compilation errors. Save as .cu or .cpp file, compile with nvcc.exe or cl.exe with the libcu++ includes.

#include <cuda/std/atomic>

struct A {
  float near;
  float far;
};

int main() { }

@nvibd
Copy link
Author

nvibd commented Mar 3, 2021

The libcu++ version is the one included with CUDA 11.2.

cl.exe version:
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29336 for x64
nvcc.exe version:
Cuda compilation tools, release 11.2, V11.2.67

@miscco
Copy link
Collaborator

miscco commented Feb 23, 2023

Unfortunately there is nothing we can do here.

@miscco miscco closed this as completed Feb 23, 2023
@nvibd
Copy link
Author

nvibd commented Feb 23, 2023

Would #undefs for near and far after "windef.h" includes inside libcu++ not be a workable fix?

@miscco
Copy link
Collaborator

miscco commented Feb 23, 2023

We cannot #undef macros from a system header.

While at the moment the macro might be useless it could get some meaning in the future leading to havoc

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants