gpt4 book ai didi

javac错误: Class names are only accepted if annotation processing is explicitly requested

转载 作者:IT老高 更新时间:2023-10-28 11:34:12 25 4
gpt4 key购买 nike

我在编译我的 java 程序时遇到这个错误:

error: Class names, 'EnumDevices', are only accepted if annotation 
processing is explicitly requested
1 error

这是 java 代码(我在 Ubuntu 上运行它)。

import jcuda.CUDA;    
import jcuda.driver.CUdevprop;
import jcuda.driver.types.CUdevice;

public class EnumDevices {

public static void main(String args[]) {
CUDA cuda = new CUDA(true);
int count = cuda.getDeviceCount();

System.out.println("Total number of devices: " + count);

for (int i = 0; i < count; i++) {

CUdevice dev = cuda.getDevice(i);
String name = cuda.getDeviceName(dev);
System.out.println("Name: " + name);
int version[] = cuda.getDeviceComputeCapability(dev);

System.out.println("Version: " +
String.format("%d.%d", version[0], version[1]));
CUdevprop prop = cuda.getDeviceProperties(dev);
System.out.println("Clock rate: " + prop.clockRate + " MHz");
System.out.println("Threads per block: " + prop.maxThreadsPerBlock);
}
}
}

这里是 javac 命令:

javac -cp /home/manish.yadav/Desktop/JCuda-All-0.3.2-bin-linux-x86_64 EnumDevices

如何编译这个程序?

最佳答案

你至少需要在这一行的文件名中添加.java扩展名:

javac -cp /home/manish.yadav/Desktop/JCuda-All-0.3.2-bin-linux-x86_64 EnumDevices

来自 official faq :

Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.

此外,在您的第二个 javac 示例中(您实际上包含了 .java),您需要包含编译所需的 all 所需的 .jar 文件。

关于javac错误: Class names are only accepted if annotation processing is explicitly requested,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5063266/

25 4 0