c++ - 编译错误 : g++-v4/tr1_impl/type_traits(226): error: expected an identifier

标签 c++ cuda gpu

当 Makefile 尝试编译 .cu (CUDA) 文件时会生成错误。

我们能够使用专门为其制作的 .hpp 自行编译它。当我们试图让它在现有 header 下编译时,它自己有一个 .cpp(换句话说,.hpp、.cpp 加上一个 .cu),我们不断收到这个奇怪的编译错误。

为了便于阅读,以下所有消息都以该目录为前缀:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/include/g++-v4/tr1_impl/

消息:

type_traits(226): error: expected an identifier
type_traits(227): error: expected a ")"
type_traits(227): error: a template argument list is not allowed in a declaration of a primary template

type_traits(229): error: expected an identifier
type_traits(230): error: expected a ")"
type_traits(230): error: a template argument list is not allowed in a declaration of a primary template

type_traits(232): error: expected an identifier
type_traits(233): error: expected a ")"
type_traits(233): error: expected a ">"

type_traits(235): error: expected an identifier
type_traits(236): error: expected a ")"
type_traits(236): error: expected a ">"

type_traits(238): error: expected an identifier
type_traits(239): error: expected a ")"
type_traits(239): error: expected a ">"

type_traits(241): error: expected an identifier
type_traits(242): error: expected a ")"
type_traits(242): error: expected a ">"

type_traits(244): error: expected an identifier
type_traits(245): error: expected a ")"
type_traits(245): error: expected a ">"

type_traits(247): error: expected an identifier
type_traits(248): error: expected a ")"
type_traits(248): error: expected a ">"

是否可以有一个 .hpp 后面有一个 .cu 和一个 .cpp?

最佳答案

是的,这是可能的,而且实际上很常见,但是如果 .hpp 包含 nvcc 无法构建的文件,那么您就不能从 .cu 中包含它。

您可以在这些文件周围使用 #ifndef __CUDACC__,这样在使用 nvcc 编译 .cu 时它们就不会被包含在内。

关于c++ - 编译错误 : g++-v4/tr1_impl/type_traits(226): error: expected an identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12849270/

相关文章:

我们可以使用 cuFFT 处理多个不同大小的文件吗?

macos - 使用 C++11 的 CUDA 6.0 的 CMake 脚本

c++ - 是否有可能让持久的 cuda 内核运行并与 cpu 异步通信?

linux - 是否可以重新启动在 Docker 容器中运行的操作系统 (linux)? (重启 GPU)

c++ - 从全局内核调用宿主函数

c++ - STL:容器的容器

C++ 生成器-Piece.cpp(20) : E2316 'Button1Click' is not a member of 'TForm'

c++ - Visual C++,Windows 更新接口(interface) (IUpdate) <wuapi.h>,get_MsrcSeverity

tensorflow - DMA 和 tensorflow 的打印是什么意思?是否可以设置它们?

c++ - 嵌套类指针访问