Mathias Grainger
Mathias Grainger

Reputation: 23

CUDA samples not compiling due to multiple redefinition errors

I just installed CUDA toolkit 7.5 on OSX 10.11 with Xcode 7. Macbook Pro with GeForce GT 750M

When compiling (make) the samples I get multiple redefinition errors. Here are the first two:

actual console output (partial)

error sample:

In file included from tmpxft_0000b964_00000000-19_asyncAPI.compute_20.cudafe1.stub.c:1: In file included from /var/folders/bm/fp5n2kzd419c4mbnsmyqf1cm0000gn/T/tmpxft_0000b964_00000000-19_asyncAPI.compute_20.cudafe1.stub.c:7: In file included from /Developer/NVIDIA/CUDA-7.5/bin/../include/crt/host_runtime.h:247: In file included from /Developer/NVIDIA/CUDA-7.5/bin/../include/common_functions.h:224: In file included from /Developer/NVIDIA/CUDA-7.5/bin/../include/math_functions.h:10219: In file included from /Developer/NVIDIA/CUDA-7.5/bin/../include/math_functions.hpp:1664: /usr/include/math.h:204:48: error: redefinition of 'inline_isfinitef' inline __attribute ((always_inline)) int inline_isfinitef(float __x) { ^ /usr/include/math.h:204:58: note: previous definition is here extern "C" { __attribute((__always_inline)) inline int __inline_isfinitef(float __x)

The errors are related to math.h includes. Interestingly some of the samples if compiled manually such as the deviceQuery sample do compile and run.

Custom code that I have written also fails with the same errors. In my code if I comment out the "math.h" and the include the errors are the same. I do include NVIDIA's cutil_math.h

I've tried changing the clang version down to 6.4 but it makes no difference. I've also tried multiple compiler flags to no avail.

Upvotes: 2

Views: 874

Answers (1)

adon
adon

Reputation: 178

I provide a solution that will fix the problem, but might cause a problem in the future.

The error is showing the sequence of includes down to where the problem is occuring. In this case 7.5/bin/../include/math_functions.hpp:1664

On line 1664 of math_functions.hpp comment out #include "math.h" and #include <cmath> below it. This will remove the redefinition and your project will no longer have this error, and the samples will compile.

Upvotes: 1

Related Questions