【发布时间】:2016-03-21 05:08:25
【问题描述】:
我有一个简单的代码,它的编译方式不同,具体取决于它是使用 .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>。我错过了什么?
【问题讨论】:
-
当我用
nvcc program.cu编译它时没有错误/警告,我只是修复了警告并且工作正常。 -
当我使用 CUDA 4.2、5.0、5.5、6.0、6.5、7.0 和 7.5 中的每一个使用 .cu 扩展名编译它时,不会产生任何错误
-
我没有。我有 Ubuntu 15.04 (64BIT) 和
Cuda compilation tools, release 6.5, V6.5.12 -
@Rafal:没有旗帜,什么都没有。我拥有的主机编译器是 gcc 4.6.3
-
如果我是你,我会提交错误报告