Gcc 莎士比亚编程语言-编译时出错

Gcc 莎士比亚编程语言-编译时出错,gcc,compiler-construction,shakespeare-lang,Gcc,Compiler Construction,Shakespeare Lang,为了将hello.spl转换为C,我运行了/spl2c hello.C,效果很好 接下来我运行gcc hello.c,但出现以下错误: 致命错误:spl.h:没有这样的文件或目录 spl.h和hello.c在同一个目录中。我试图将hello.c中的include语句从#include更改为#include“spl.h”,但在运行gcc hello.c时出现了几个错误,例如: global\u initialize'的未定义引用 对“初始化字符”的未定义引用 有人能告诉我发生了什么吗?函数glob

为了将
hello.spl
转换为C,我运行了
/spl2c hello.C
,效果很好

接下来我运行
gcc hello.c
,但出现以下错误:

致命错误:spl.h:没有这样的文件或目录

spl.h
hello.c
在同一个目录中。我试图将
hello.c
中的include语句从
#include
更改为
#include“spl.h”
,但在运行
gcc hello.c
时出现了几个错误,例如:

global\u initialize'的未定义引用

对“初始化字符”的未定义引用


有人能告诉我发生了什么吗?

函数global\u initilize,initialize\u character在hello.c中声明,但没有定义。我认为您的程序hello.c依赖于一个库(“spl”library?),它不包含在您的compile命令中

您应该具备以下条件之一:

gcc hello.c whatever_file_who_define_undefined_function.c
gcc hello.c -lwhatever_lib_that_define_undefined_function.so
gcc hello.c -Ipath/to/spl/include/ -Lpath/to/spl/library -llibspl.a
编辑:

您需要包含libspl.a库才能使其正常工作

因此,编译选项应如下所示:

gcc hello.c whatever_file_who_define_undefined_function.c
gcc hello.c -lwhatever_lib_that_define_undefined_function.so
gcc hello.c -Ipath/to/spl/include/ -Lpath/to/spl/library -llibspl.a
  • -I
    选项指定spl.h文件的位置
  • -L
    选项指定libspl.a的位置
  • -l
    选项指定要使用的库
或者(*.a是静态库,因此它可以像对象文件一样处理)


这是我键入的命令,但我得到了错误“ld:library not found for-llibspl.a”使其正常工作。我要做的是运行spl2c,然后将hello.c文件中的include语句更改为包含“spl.h”(用引号括起来,而不是尖括号括起来)。然后我运行了gcc hello.c libspl.a,最后运行了./a.out。当您执行
时,它首先查看系统头文件(如stdio.h等),如果没有找到本地头文件的编译查找。应该没有问题,特别是如果指定了
-I
选项……如果您让它工作起来,那么它就很酷了。我很高兴能帮上忙:)