c2v
c2v copied to clipboard
Cannot convert C file to V
I tried following the demo, and copied the primes.c
file to a file called main.c
which has the following code:
#include <stdio.h>
#include <stdbool.h>
_Bool is_prime(int num) {
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) return false;
}
return true;
}
int main() {
for (int i = 1; i < 100; i++) {
if (is_prime(i)) {
printf("%i\n", i);
}
}
return 0;
}
I validated the code is working by running
gcc main.c -o run.exe
run
and it worked as exxpected.
Then I tried running v translate main.c
and got the following error:
C to V translator 0.3.1
translating main.c ...
The file main.c could not be parsed as a C source file.
C2V command: "C:\Users\Unicorn\.vmodules\c2v\c2v.exe" "main.c"
C2V failed to translate the C files. Please report it via GitHub.
I don't know if this is Windows specific, the version of clang you have, or what, but it works correctly here, on Linux, using V 0.3.3 2179db3
and clang version 15.0.7
:
$ vi main.c
[jalon@7950x ~]$ gcc main.c -o run
[jalon@7950x ~]$ ./run
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$ v translate main.c
C to V translator 0.3.1
translating main.c ... No more children
No more children
Reformatted file: /home/jalon/main.v
took 406 ms ; output .v file: main.v
Translated 1 files in 406 ms.
[jalon@7950x ~]$ v run main.v
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[jalon@7950x ~]$
So... which version of clang do you have? If you don't have the one from https:\\winlibs.com
, I recommend uninstalling what you have now, and getting that one.
I don't know if this is Windows specific, the version of clang you have, or what, but it works correctly here, on Linux, using
V 0.3.3 2179db3
andclang version 15.0.7
:$ vi main.c [jalon@7950x ~]$ gcc main.c -o run [jalon@7950x ~]$ ./run 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 [jalon@7950x ~]$ v translate main.c C to V translator 0.3.1 translating main.c ... No more children No more children Reformatted file: /home/jalon/main.v took 406 ms ; output .v file: main.v Translated 1 files in 406 ms. [jalon@7950x ~]$ v run main.v 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 [jalon@7950x ~]$
So... which version of clang do you have? If you don't have the one from
https:\\winlibs.com
, I recommend uninstalling what you have now, and getting that one.
I downloaded MinGW64 and it came with clang...
Everyone using V on Windows has had much better luck with the gcc/clang package from https://winlibs.com - it is a much more up-to-date package than the one from mingw, usually.
Everyone using V on Windows has had much better luck with the gcc/clang package from https://winlibs.com - it is a much more up-to-date package than the one from mingw, usually.
This is exactly what I downloaded....
I faced the same issue on Windows 10 trying to run v translate
on an example from the docs. I already had gcc from MinGW package that works ok with compiling C files, but not with c2v. Then I installed clang with llvm package, and now c2v works without errors.
Same issue, also on Windows. By the way I also downloaded clang from winlibs.
clang with llvm package
Could you share the link for this, please?
Look on https://winlibs.com - you have a choice of downloading gcc either WITH, or WITHOUT clang/llvm/ldb/lldb
Just choose one of the links to the left, instead of the right (after the text about "without...").
Up to version 14.1.0 there, now.