gpt4 book ai didi

c - 如何在 MacOS 10.12 上编译 STUTTER lag

转载 作者:行者123 更新时间:2023-11-30 14:32:41 26 4
gpt4 key购买 nike

我目前正在阅读 Gary W Flake 写的 super 好书《自然的计算之美》,他在书中介绍了 Stutter language 。我正在尝试在 MacOSX 10.12.6 (Sierra) 上安装它。

TL;DR:最终解决方案是:

  • 编辑 stutter/Makefileshell/Makefile 并将所有 -g root 实例替换为 -gwheel > 或 -g sys
  • 运行以下命令(sudo 是必要的):
sudo IA64=1 CFLAGS='-std=gnu89' PREFIX=/usr/local make install

请参阅下面的原始问题,并阅读 rici 的答案以了解为什么 CFLAGS 必须这样设置。

如安装文件中所述,唯一的依赖项是:gccgnu makelibreadline-dev(对于 shell)和libsqlite3-dev (用于可选的 sqlite 模块)。我确保它们是使用自制软件安装的,准确地说我有:

  • gcc 9.1.0(通过gcc --version获得)
  • make 3.81(通过make --version获得)
  • readline 8.0.1(通过brew install readline获得并让brew输出已安装的版本)
  • sqlite 3.30.1(通过brew install sqlite3获得并让brew输出已安装的版本)

安装失败并出现以下跟踪:

Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ make install
cd stutter && make install
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o read.o read.c
In file included from read.c:7:
In file included from ./builtins.h:5:
./memory.h:29:14: warning: inline function 'xcalloc' is not defined
[-Wundefined-inline]
inline void *xcalloc(size_t nmemb, size_t size);
^
read.c:15:18: note: used here
read_state *s = xcalloc(1, sizeof(read_state));
^
In file included from read.c:7:
In file included from ./builtins.h:5:
./memory.h:31:14: warning: inline function 'xmalloc' is not defined
[-Wundefined-inline]
inline void *xmalloc(size_t size);
^
read.c:54:23: note: used here
s->token = (char *) xmalloc(8);
^
In file included from read.c:7:
In file included from ./builtins.h:5:
./memory.h:33:14: warning: inline function 'xrealloc' is not defined
[-Wundefined-inline]
inline void *xrealloc(void *ptr, size_t size);
^
read.c:62:24: note: used here
s->token = (char *) xrealloc(s->token, s->buflen *= 2);
^
3 warnings generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o types.o types.c
In file included from types.c:10:
./memory.h:29:14: warning: inline function 'xcalloc' is not defined
[-Wundefined-inline]
inline void *xcalloc(size_t nmemb, size_t size);
^
types.c:56:23: note: used here
if(!o) o = (s_obj *) xcalloc(1, sizeof(s_obj));
^
In file included from types.c:10:
./memory.h:31:14: warning: inline function 'xmalloc' is not defined
[-Wundefined-inline]
inline void *xmalloc(size_t size);
^
types.c:151:31: note: used here
o->d.string.value = (char *) xmalloc(len + 1);
^
In file included from types.c:10:
./memory.h:33:14: warning: inline function 'xrealloc' is not defined
[-Wundefined-inline]
inline void *xrealloc(void *ptr, size_t size);
^
types.c:1013:26: note: used here
typedb = (typeinfo *) xrealloc(typedb, typedb_si...
^
In file included from types.c:12:
./builtins.h:113:12: warning: inline function 'nextparm' is not defined
[-Wundefined-inline]
inline int nextparm(s_obj **obj, s_obj **parm);
^
types.c:1378:8: note: used here
while(nextparm(&o, &iter)) {
^
4 warnings generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o memory.o memory.c
memory.c:160:18: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_protect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:166:20: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_unprotect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:474:16: warning: cast to 's_obj *' (aka 'struct s_obj *') from smaller
integer type 'int' [-Wint-to-pointer-cast]
gc_mark_obj((s_obj *) ((ptrint) (p->root) ^ 1));
^
3 warnings generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o eval.o eval.c
In file included from eval.c:8:
./builtins.h:113:12: warning: inline function 'nextparm' is not defined
[-Wundefined-inline]
inline int nextparm(s_obj **obj, s_obj **parm);
^
eval.c:130:9: note: used here
while(nextparm(&i, &parm)) {
^
In file included from eval.c:5:
In file included from ./eval.h:10:
./memory.h:138:13: warning: inline function 'gc_protlist_add' is not defined
[-Wundefined-inline]
inline void gc_protlist_add(s_obj *obj);
^
eval.c:138:4: note: used here
gc_protlist_add(o);
^
In file included from eval.c:5:
In file included from ./eval.h:10:
./memory.h:31:14: warning: inline function 'xmalloc' is not defined
[-Wundefined-inline]
inline void *xmalloc(size_t size);
^
eval.c:1087:24: note: used here
compx *cx = (compx *) xmalloc(sizeof(compx));
^
3 warnings generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o builtins.o builtins.c
In file included from builtins.c:56:
In file included from ./stutter.h:5:
./memory.h:31:14: warning: inline function 'xmalloc' is not defined
[-Wundefined-inline]
inline void *xmalloc(size_t size);
^
builtins.c:513:18: note: used here
p = (char *) xmalloc(strlen(obj->d.symbo...
^
In file included from builtins.c:56:
In file included from ./stutter.h:5:
./memory.h:33:14: warning: inline function 'xrealloc' is not defined
[-Wundefined-inline]
inline void *xrealloc(void *ptr, size_t size);
^
builtins.c:856:21: note: used here
str = (char *) xrealloc(str, stra);
^
In file included from builtins.c:56:
In file included from ./stutter.h:5:
./memory.h:29:14: warning: inline function 'xcalloc' is not defined
[-Wundefined-inline]
inline void *xcalloc(size_t nmemb, size_t size);
^
builtins.c:2025:11: note: used here
*data = xcalloc(1, 8 + 2 * sizeof(int));
^
3 warnings generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o mathbuiltins.o mathbuiltins.c
In file included from mathbuiltins.c:5:
./builtins.h:116:12: warning: inline function 'nextarg' is not defined
[-Wundefined-inline]
inline int nextarg(varctx *ctx, s_obj **obj, s_obj **parm);
^
mathbuiltins.c:14:6: note: used here
if(!nextarg(ctx, &obj, &parm))
^
1 warning generated.
cc -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o sforms.o sforms.c
In file included from sforms.c:2:
In file included from ./stutter.h:7:
./builtins.h:113:12: warning: inline function 'nextparm' is not defined
[-Wundefined-inline]
inline int nextparm(s_obj **obj, s_obj **parm);
^
sforms.c:27:6: note: used here
if(!nextparm(&prm, &parm))
^
In file included from sforms.c:2:
In file included from ./stutter.h:7:
./builtins.h:116:12: warning: inline function 'nextarg' is not defined
[-Wundefined-inline]
inline int nextarg(varctx *ctx, s_obj **obj, s_obj **parm);
^
sforms.c:166:7: note: used here
if(!nextarg(ctx, &obj, &asg)) {
^
In file included from sforms.c:2:
In file included from ./stutter.h:5:
./memory.h:29:14: warning: inline function 'xcalloc' is not defined
[-Wundefined-inline]
inline void *xcalloc(size_t nmemb, size_t size);
^
sforms.c:388:47: note: used here
method->d.clos_method.args = (method_arg *) xcalloc(argn...
^
3 warnings generated.
cc -shared -o libstutter-0.16.so read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o -L/usr/local/opt/readline/lib -lm
Undefined symbols for architecture x86_64:
"_gc_follow", referenced from:
_gc_mark_obj in memory.o
_gc_mark in memory.o
"_gc_harvest", referenced from:
_gc_sweep in memory.o
"_gc_protlist_add", referenced from:
_gc_record in memory.o
_funcexec in eval.o
"_nextarg", referenced from:
_next_t in builtins.o
_sb_set in builtins.o
_sb_setg in builtins.o
_sb_scar in builtins.o
_sb_consdump in builtins.o
_sb_cons in builtins.o
_sb_list in builtins.o
...
"_nextargtail", referenced from:
_sb_begin in builtins.o
_sb_cond in builtins.o
"_nextparm", referenced from:
_build_class_ancestry in types.o
_slots_merge in types.o
_class_calculate in types.o
_build_precedence_branch in types.o
_build_precedence in types.o
_update_generic_nexts in types.o
_find_next_method in types.o
...
"_xcalloc", referenced from:
_create_read_state in read.o
_alloc_s_obj in types.o
_alloc_ungc_obj in types.o
_create_eof in types.o
_create_t in types.o
_create_nil in types.o
_create_dict in types.o
...
"_xmalloc", referenced from:
_token_appch in read.o
_create_string_counted in types.o
_stream_printf in types.o
_weak_reference in types.o
_gc_alloc_protroot in memory.o
_varctx_create in memory.o
_stutter_init in memory.o
...
"_xrealloc", referenced from:
_token_appch in read.o
_gettypeid in types.o
_slots_merge in types.o
_gc_prot_free in memory.o
_gc_record in memory.o
_mark_miscfree in memory.o
_gc_sweep in memory.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libstutter-0.16.so] Error 1
make: *** [install] Error 2

似乎存在内存分配库未正确加载的问题,但是,是的,至少可以说,我对 C 的了解不是很好。欢迎任何帮助。请注意,文档本身表明安装仅针对 Linux 进行了测试,因此可能需要进行一些修改才能适用于 Mac OSX。

谢谢!

编辑1:回应rici的回答。首先感谢您的快速答复。我尝试了你的解决方案,如下所示:

Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ IA64=1 CFLAGS=gnu89 make install
cd stutter && make install
cc gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o read.o read.c
clang: error: no such file or directory: 'gnu89'
make[1]: *** [read.o] Error 1
make: *** [install] Error 2

我猜 CFLAGS 格式错误,所以我尝试了以下操作,这又带来了另一个错误,这让我觉得我们还遗漏了其他东西:

Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ IA64=1 CFLAGS='-std=gnu89' make install 
cd stutter && make install
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o read.o read.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o types.o types.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o memory.o memory.c
memory.c:160:18: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_protect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:166:20: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_unprotect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:474:16: warning: cast to 's_obj *' (aka 'struct s_obj *') from smaller
integer type 'int' [-Wint-to-pointer-cast]
gc_mark_obj((s_obj *) ((ptrint) (p->root) ^ 1));
^
3 warnings generated.
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o eval.o eval.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o builtins.o builtins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o mathbuiltins.o mathbuiltins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/share/stutter\" -I/usr/local/opt/readline/include -c -o sforms.o sforms.c
cc -shared -o libstutter-0.16.so read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o -L/usr/local/opt/readline/lib -lm
rm -f libstutter.so
ln -s libstutter-0.16.so libstutter.so
rm -f libstutter.a
ar scq libstutter.a read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o
ranlib libstutter.a
install -o root -g root -m755 -d /usr/lib
install: root: Invalid argument
make[1]: *** [install] Error 67
make: *** [install] Error 2

您知道这个新错误发生了什么吗?不知何故 root 似乎是无效的参数?

编辑2:我从中发现了unrelated github thread OSX 上不存在 root 组,因此我手动编辑 shell/Makefilestutter/Makefile 来替换 的所有实例-g root by -gwheel 按照线程中的建议。我越来越接近了,但现在面临一个新错误:

Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ IA64=1 CFLAGS='-std=gnu89' PREFIX=/usr/local make install 
cd stutter && make install
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o read.o read.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o types.o types.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o memory.o memory.c
memory.c:160:18: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_protect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:166:20: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_unprotect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:474:16: warning: cast to 's_obj *' (aka 'struct s_obj *') from smaller
integer type 'int' [-Wint-to-pointer-cast]
gc_mark_obj((s_obj *) ((ptrint) (p->root) ^ 1));
^
3 warnings generated.
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o eval.o eval.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o builtins.o builtins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o mathbuiltins.o mathbuiltins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -I/usr/local/opt/readline/include -c -o sforms.o sforms.c
cc -shared -o libstutter-0.16.so read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o -L/usr/local/opt/readline/lib -lm
rm -f libstutter.so
ln -s libstutter-0.16.so libstutter.so
rm -f libstutter.a
ar scq libstutter.a read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o
ranlib libstutter.a
install -o root -g sys -m755 -d /usr/local/lib
install: chown 0:3 /usr/local/lib: Operation not permitted
install -o root -g sys -m755 -d /usr/local/include/stutter
install: chown 0:3 /usr/local/include/stutter: Operation not permitted
install -o root -g sys -m755 -d /usr/local/share/stutter
install: chown 0:3 /usr/local/share/stutter: Operation not permitted
install -o root -g sys -m755 libstutter-0.16.so libstutter.so libstutter.a /usr/local/lib
install: /usr/local/lib/libstutter-0.16.so: chown/chgrp: Operation not permitted
make[1]: *** [install] Error 71
make: *** [install] Error 2

这似乎与 this thread 有关其中指出 High Sierra 不再允许在 /usr/local 中进行 chown。但不知道如何摆脱这种情况。

编辑4:只需添加sudo就可以了,在顶部添加了最终的解决方案。

Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ sudo IA64=1 CFLAGS='-std=gnu89' PREFIX=/usr/local make install 
cd stutter && make install
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o read.o read.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o types.o types.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o memory.o memory.c
memory.c:160:18: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_protect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:166:20: warning: cast to 'varctx *' (aka 'struct varctx *') from
smaller integer type 'int' [-Wint-to-pointer-cast]
gc_unprotect_root((varctx *) ((ptrint)obj | 1));
^
memory.c:474:16: warning: cast to 's_obj *' (aka 'struct s_obj *') from smaller
integer type 'int' [-Wint-to-pointer-cast]
gc_mark_obj((s_obj *) ((ptrint) (p->root) ^ 1));
^
3 warnings generated.
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o eval.o eval.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o builtins.o builtins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o mathbuiltins.o mathbuiltins.c
cc -std=gnu89 -g -Wall -DVERSION=\"0.16\" -DREFPATH=\"/usr/local/share/stutter\" -c -o sforms.o sforms.c
cc -shared -o libstutter-0.16.so read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o -lm
rm -f libstutter.so
ln -s libstutter-0.16.so libstutter.so
rm -f libstutter.a
ar scq libstutter.a read.o types.o memory.o eval.o builtins.o mathbuiltins.o sforms.o
ranlib libstutter.a
install -o root -g sys -m755 -d /usr/local/lib
install -o root -g sys -m755 -d /usr/local/include/stutter
install -o root -g sys -m755 -d /usr/local/share/stutter
install -o root -g sys -m755 libstutter-0.16.so libstutter.so libstutter.a /usr/local/lib
install -o root -g sys -m644 lib/* /usr/local/share/stutter
install -o root -g sys -m644 types.h memory.h eval.h builtins.h stutter.h read.h /usr/local/include/stutter
cd shell && make install
cc -c -o main.o main.c -std=gnu89 -I../stutter
main.c:26:9: warning: implicitly declaring library function 'strlen' with type
'unsigned long (const char *)' [-Wimplicit-function-declaration]
len = strlen(text);
^
main.c:26:9: note: include the header <string.h> or explicitly provide a
declaration for 'strlen'
main.c:39:6: warning: implicitly declaring library function 'strncasecmp' with
type 'int (const char *, const char *, unsigned long)'
[-Wimplicit-function-declaration]
if(strncasecmp(name, text, len) == 0)
^
main.c:39:6: note: include the header <strings.h> or explicitly provide a
declaration for 'strncasecmp'
main.c:40:11: warning: implicitly declaring library function 'strdup' with type
'char *(const char *)' [-Wimplicit-function-declaration]
return strdup(name);
^
main.c:40:11: note: include the header <string.h> or explicitly provide a
declaration for 'strdup'
main.c:96:21: warning: implicitly declaring library function 'isspace' with type
'int (int)' [-Wimplicit-function-declaration]
if(*c && beg && !isspace(*c))
^
main.c:96:21: note: include the header <ctype.h> or explicitly provide a
declaration for 'isspace'
4 warnings generated.
cc -o stt main.o -lstutter -L../stutter -lm -lreadline
install -o root -g sys -m755 -d /usr/local/bin
install -o root -g sys -m755 stt /usr/local/bin
Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ ls
INSTALL Makefile README doc/ shell/ stutter/ tests/
Guillaume@Guillaumes-MacBook-Pro:~/Downloads/stutter-0.16$ stt
Welcome to STUTTER 0.16

>

是啊!非常感谢你rici!

最佳答案

这里的问题是源代码是为旧版本的 GCC 编写的,它对 inline 使用了自己特殊的非标准语义。声明。 inline声明后来被纳入 C 标准,但语义略有不同。

GCC 允许您使用 -std 进行指定命令行选项 用于编译源代码的几种可能标准之一,包括包含 GNU 扩展的选项。多年来默认-std设置为 gnu89 ,即带有(许多)GNU 扩展的原始 ANSI C 标准,包括 inline 的 GNU 提案。 GCC 的最新版本使用默认值 gnu99 ,它允许使用具有(较少)GNU 扩展的 C99;在此版本中,inline携带C标准语义。

由于您安装的GCC默认使用C99+gnu,所以STUTTER源代码将无法正确编译。 (这不仅限于 OS X;它在 Linux 上也存在同样的问题。)因此您需要告诉 GCC 使用 -std=gnu89为了重现编写源代码的标准。 (您也可以修复源代码,但这将需要更多工作。)

要重新编译项目,您首先需要清除已经执行的错误编译。您可以从下载的 tarball 中重新创建构建文件,但似乎以下内容可行:

make clean
IA64=1 CFLAGS=-std=gnu89 make install

(根据 INSTALLIA64=1 表明您正在 64 位系统上构建,我想您也是如此。)

关于c - 如何在 MacOS 10.12 上编译 STUTTER lag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59717481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com