-1

我意识到这可能已经回答了,但我就是找不到。使用“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
4

1 回答 1

6

cs50 页面来看,您可能需要-lcs50在命令末尾类似的内容cc


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

cc example.c cs50.o -o example
于 2014-02-27T20:36:54.340 回答