gpt4 book ai didi

c++ - Linux 上的 CUDA 编译错误,但 Windows Visual Studio 成功

转载 作者:行者123 更新时间:2023-11-28 02:10:59 25 4
gpt4 key购买 nike

这个程序可以在 Windows - Visual Studio 12 上成功构建,但在 Linux 上编译时遇到一些问题。

编译命令:nvcc main.cu

int main(int argc, char **argv) {

... (Skip some code)

// Read file.
MemoryBuffer<char> text(size + 1); // size type is size_t
auto text_smem = text.CreateSync(size);
fread(text_smem.get_cpu_wo(), 1, size, fp);

... (Skip some code)

}

编译器错误信息:

  1. auto text_smem = text.CreateSync(size);

    发生在 error: explicit type is missing ("int" assumed) error: no suitable conversion function from "SyncedMemory<char>" to "int" exists

  2. fread(text_smem.get_cpu_wo(), 1, size, fp);

    发生在 error: expression must have class type

如何解决 Linux 操作系统的编译错误?


MemoryBuffer是一个类,详细代码见here .

最佳答案

这取决于您安装的 CUDA 工具包的版本,但我想您可以尝试对 nvcc 使用 --std=c++11 选项,为了明确启用现代 C++ 功能。

引用https://devblogs.nvidia.com/parallelforall/power-cpp11-cuda-7/

To enable C++11 support, pass the flag --std=c++11 to nvcc (this option is not required for Microsoft Visual Studio).

关于c++ - Linux 上的 CUDA 编译错误,但 Windows Visual Studio 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35682619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com