write-a-C-interpreter
write-a-C-interpreter copied to clipboard
代码在windows gcc-6.3.0下无法编译通过
您好~我直接从仓库拉代码下来无法编译通过: os: win10 64bit gcc: MinGW.org GCC-6.3.0-1
PS C:\Users\AlexC\Documents\GitHub\write-a-C-interpreter> gcc -m32 -o xc xc.c
xc.c: In function 'next':
xc.c:111:57: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (current_id[Hash] == hash && !memcmp((char *)current_id[Name], last_pos, src - last_pos)) {
^
xc.c:121:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
current_id[Name] = (int)last_pos;
^
xc.c:188:29: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
token_val = (int)last_pos;
^
xc.c: In function 'expression':
xc.c:363:30: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
data = (char *)(((int)data + sizeof(int)) & (-sizeof(int)));
^
xc.c:363:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
data = (char *)(((int)data + sizeof(int)) & (-sizeof(int)));
^
xc.c:629:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*addr = (int)(text + 3);
^
xc.c:633:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*addr = (int)(text + 1);
^
.....
编译模板代码的时候会报open
,read
,close
未定义先使用的错误:
PS C:\Users\AlexC\Documents\compiler> gcc -m32 .\compiler.c .\helloworld.c
.\compiler.c: In function 'main':
.\compiler.c:46:15: warning: implicit declaration of function 'open' [-Wimplicit-function-declaration]
if ((fd = open(*argv, 0)) < 0) {
^~~~
.\compiler.c:56:14: warning: implicit declaration of function 'read' [-Wimplicit-function-declaration]
if ((i = read(fd, src, poolsize-1)) <= 0) {
^~~~
.\compiler.c:61:5: warning: implicit declaration of function 'close' [-Wimplicit-function-declaration]
close(fd);
在论坛上找到相似问题,但还是无法解决,如引入以下头文件:
#include <fcntl.h> // for open
#include <unistd.h> // for close
是我本地的gcc版本有问题吗?还是必须要在linux环境下运行?
@AlexChingEraser 一般 warning 错误应该不影响编译,有 error 错误吗?
没有error,但是程序会退出,显示usage:[-s] [-d] file ...
没有error,但是程序会退出,显示usage:[-s] [-d] file ...
是怎么运行的?显示 usage: ....
代表你需要传入要运行的 c 文件,例如:
./xc hello.c
./xc -s hello.c
./xc xc.c hello.c
./xc xc.c xc.c hello.c
这个在wimdows上就会这样,我在linux上跑就没问题了