我从 Don Knuth 下载了一个 CWEB 程序 — 特别是
http://www-cs-faculty.stanford.edu/~knuth/programs/sliding.w 。
我将 sliding.w
转换为 sliding.c
。
现在我尝试使用以下方法编译它:
gcc sliding.c -o sliding
但后来我得到:
./sliding.w:116:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main(int argc, char *argv[])
^
/tmp/cc9NVnXq.o: In function `main':
sliding.c:(.text+0x2006): undefined reference to `gb_init_rand'
sliding.c:(.text+0x201c): undefined reference to `gb_fptr'
sliding.c:(.text+0x202b): undefined reference to `gb_fptr'
sliding.c:(.text+0x2036): undefined reference to `gb_fptr'
sliding.c:(.text+0x2047): undefined reference to `gb_flip_cycle'
collect2: error: ld returned 1 exit status
有人可以帮助我吗?
最佳答案
第一个问题只是一个警告。 fatal error 是您缺少 gb_
符号,这些符号在此处定义:
http://ftp.cs.stanford.edu/pub/sgb/gb_flip.w
所以首先需要将 gb_flip.w 编译成 .c 文件,然后将两个 .c 文件一起编译,如下所示:
gcc sliding.c gb_flip.c -o sliding
关于从 Knuth 编译 CWEB 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47491632/