Error when trying to compile a program with '.c' extension
When trying to compile the sample program shown bellow with the '.c' extension it gives this error:
circle -o hello hello.c
error: target declarations:1:1
undeclared identifier 'class'
enum class nvvm_arch_t {
^
error: target declarations:3:1
undeclared identifier 'class'
enum class amdgpu_arch_t {
^
error: target declarations:17:23
undeclared identifier 'nvvm_arch_t'
@codegen extern const nvvm_arch_t __nvvm_arch;
^
error: target declarations:20:23
undeclared identifier 'amdgpu_arch_t'
@codegen extern const amdgpu_arch_t __amdgpu_arch;
^
hello.c:
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello !\n");
return 0;
}
If we change the extension to '.cpp' then it compiles fine.
@seanbaxter I've also experienced this same problem, but instead I patched the binary to get around the issue (but most likely breaking CUDA, which is fine for my test purpose.)
@mingodad You can workaround this by using -x=c++ but this has side effects, of course, see output of diff -U0 <(./circle -x=c -E -dM /dev/null) <(./circle -x=c++ -E -dM /dev/null) just to start.
Here's the fast hack I used to get plain C working with the distributed Build 200 binary:
$ radiff2 ./circle.orig ./circle
0x02849a10 636c617373 => 2020202020 0x02849a10
0x02849a30 636c617373 => 2020202020 0x02849a30
0x02849bf9 4063 => 2f2f 0x02849bf9
0x02849c57 4063 => 2f2f 0x02849c57
In addition to @johnsonjh's answer, one can also use -xc++, similarly to GCC, Clang, et al.
Thank you for all your suggestions !
Another way is to create a wrapper and include the C files:
cppwrapper.cpp:
extern "C" {
#include "cfile";
}