【发布时间】:2014-02-26 20:24:21
【问题描述】:
您好,我对编程世界完全陌生,我正在尝试在线学习哈佛的 CS50 课程。
在制作“Hello World”程序时,我下载了“cs50.h”来定义GetString 和string(至少我认为)。所以这是我写的代码:
文件.c:
#include "cs50.h"
#include <stdio.h>
int main(int argc, string argv[])
{
string name;
printf("Enter your name: ");
name = GetString();
printf("Hello, %s\n", name);
}
但是,每当我尝试make file 时,就会发生这种情况:
cc file.c -o file
Undefined symbols for architecture x86_64:
"_GetString", referenced from:
_main in file-JvqYUC.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: *** [file] Error 1
如果有帮助,这里是 cs50.h 文件的链接:http://dkui3cmikz357.cloudfront.net/library50/c/cs50-library-c-3.0/cs50.h
我想知道为什么会出现此错误以及如何解决它。请帮忙。
【问题讨论】:
-
这是 C,而不是 C++(
string是 typedef,而不是std::string)。请仅标记适当的语言(C 和 C++ 不同)。删除 C++ 标签。 -
cc file.c cs50.c -o file或cc file.c cs50.o -o file