使用string.h时出现makefile错误

时间:2014-02-27 20:32:29

标签: c cs50

我意识到这可能已得到解答,但我找不到它。使用“make”编译以下文件时:

#include <cs50.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    // get line of text
string s = GetString();

// print string, one character per line
for (int i = 0; i < strlen(s); i++)
{
    char c = s[i];
    printf("%c\n", c);
}
return 0;
}

我收到以下消息:

$ make example
cc     example.c   -o example
Undefined symbols for architecture x86_64:
  "_GetString", referenced from:
      _main in example-iPNXBe.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: *** [example] Error 1

1 个答案:

答案 0 :(得分:6)

the cs50 page判断,您可能需要-lcs50命令末尾的cc


或者您可以使用cs50.o目标文件并与之链接。

cc example.c cs50.o -o example