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

Compilation fails when including complex.h #1244

Closed
wkjung opened this issue Jul 24, 2020 · 3 comments · Fixed by #1270
Closed

Compilation fails when including complex.h #1244

wkjung opened this issue Jul 24, 2020 · 3 comments · Fixed by #1270
Assignees
Milestone

Comments

@wkjung
Copy link

wkjung commented Jul 24, 2020

Hi.

With nvcc V11.0.194 (g++ -v outputs (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0), I tried to compile the code below:
a.cu

#include <complex.h>
#include <thrust/copy.h>

But I got these errors:

~/thrust/thrust/iterator/constant_iterator.h(220): error #40: expected an identifier
~/thrust/thrust/iterator/constant_iterator.h(222): error #79: expected a type specifier
~/thrust/thrust/iterator/constant_iterator.h(222): error #79: expected a type specifier

Is it a bug or intended behavior? Thanks.

@alliepiper
Copy link
Collaborator

That's troubling.

It does seem to compile if the headers are reversed as a work around:

$ cat a.cu
#include <thrust/copy.h>
#include <complex.h>

$ nvcc -c tt.cu; echo $?
0

@dkolsen-pgi
Copy link
Collaborator

<complex.h> defines a macro named I, which represents the unit imaginary number. That clashes with any uses of the identifier I in any code after the include of <complex.h>. It would be good if Thrust were changed to not use the identifier I anywhere. There are not a lot, and the change should be simple, but there are several files in addition to <thrust/iterator/constant_iterator.h>.

@alliepiper alliepiper added this to the 1.10.0 milestone Aug 7, 2020
@alliepiper
Copy link
Collaborator

Thanks for the explanation, @dkolsen-pgi, I'm surprised I've never encountered that before.

We should fix this at some point.

@alliepiper alliepiper self-assigned this Sep 3, 2020
alliepiper added a commit to alliepiper/thrust that referenced this issue Sep 3, 2020
Fix places where using `I` for an identifier was causing conflicts
with complex.h.

Fixes NVIDIA#1244.
alliepiper added a commit to alliepiper/thrust that referenced this issue Sep 3, 2020
Fix places where using `I` for an identifier was causing conflicts
with complex.h.

Fixes NVIDIA#1244.
alliepiper added a commit to brycelelbach/cub_historical_2019_2020 that referenced this issue Sep 9, 2020
alliepiper added a commit to alliepiper/thrust that referenced this issue Sep 9, 2020
Fix places where using `I` for an identifier was causing conflicts
with complex.h.

Fixes NVIDIA#1244.
alliepiper added a commit that referenced this issue Sep 9, 2020
Fix places where using `I` for an identifier was causing conflicts
with complex.h.

Fixes #1244.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants