我在Mac OSX Lion上编译一个非常简单的name.c文件时遇到了一些问题.
现在,我开始在cs50.net上关注哈佛CS50课程.我不是全新的编程,但我很好奇这门课程的教学方式.
这是name.c的来源:
#include <stdio.h>
#include <cs50.h>
int
main(void)
{
printf("State your name:\n");
string name = GetString();
printf("O hai, %s!\n", name);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它需要这个库:https://manual.cs50.net/CS50_Library.
现在,当我编译它时,会发生这种情况:
Undefined symbols for architecture x86_64:
"_GetString", referenced from:
_main in name-vAxcar.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: *** [name] Error 1
Run Code Online (Sandbox Code Playgroud)
如果我在源文件中使用相同的GetString()cs50.c函数,它可以完美地工作:
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <limits.h>
#include <stdbool.h> …Run Code Online (Sandbox Code Playgroud)