我有一个简单的代码,它的编译方式有所不同,具体取决于它是使用 .c 还是 .cu 扩展名保存:
#include <stdio.h>
#include <complex.h>
int main()
{
float num;
float eps_i, eps_s, tau_d, sigma;
float pi, wave_freq, eps_0;
eps_i = 43.0;
eps_s = 2.4;
tau_d = 0.3;
sigma = 4.75;
pi = 3.14;
wave_freq = 0.015;
eps_0 = 40.234;
float complex c1 = 0.0 + 2.0 * pi * wave_freq * tau_d * I;
float complex c2 = 0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I;
num = creal(eps_i + (eps_s - eps_i) / (1.0 + (0.0 + 2.0 * pi * wave_freq * tau_d * I)) -
(0.0 + sigma / (2.0 * pi * wave_freq * eps_0) * I));
printf("%g\n", num);
}
如果我使用 nvcc test.c
编译它它的工作原理完全符合我的预期。但是,如果我运行 nvcc test.cu
我得到:
test.cu(18): error: expected a ";"
test.cu(19): error: "complex" has already been declared in the current scope
test.cu(19): error: expected a ";"
test.cu(21): error: identifier "I" is undefined
test.cu(21): error: identifier "creal" is undefined
test.cu(18): warning: variable "complex" was declared but never referenced
test.cu(19): warning: variable "complex" was declared but never referenced
5 errors detected in the compilation of "/var/folders/3z/8bl4b3yx0c3_5tgf35dr_z180000gp/T//tmpxft_00015a75_00000000-9_test.cpp1.ii".
我知道 .cu 被视为包含 CUDA 代码的代码,而 .c 只是主机代码,但我希望它们在这种情况下表现相同。请注意,它不会提示 #include <complex.h>
根本不。我错过了什么?
最佳答案
从评论来看,此问题似乎特定于 OS X El Capitan 上具有最新 XCode 的 CUDA 7.5。提供的重现案例似乎适用于测试过的所有其他平台。建议向 NVIDIA 提交错误报告。
[此答案已添加为社区 wiki 条目,以便将此问题从未解答的列表中删除]
关于c - 在 Mac OS X 10.11 上,如果与 .cu 扩展名一起使用,nvcc 不喜欢复杂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288725/