问题描述
我对编程并不陌生,但与专家相距甚远。我正在从哈佛大学在线获取CS50,并且尝试使用cs50库中的功能,这些功能应该可以自动工作在cs50设备(Fedora虚拟机版本19-2)中。我的问题是,当我 #include< cs50.h>
像他在讲座中一样进行编译时,我收到一条错误消息。
I'm not new to programming but I'm also far from an expert. I'm taking CS50 from Harvard online and I'm trying to use the functions from the cs50 library that are supposed to work automatically inside the cs50 appliance (Fedora virtual machine version 19-2). My problem is that when I #include <cs50.h>
and compile like he does in the lectures, I get an error message.
这是一个来自演讲幻灯片的简单程序。
Here's a simple program from a lecture slide.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// ask user for input
printf("Give me an integer: ");
int x = GetInt();
printf("Give me another integer: ");
int y = GetInt();
// do the math
printf("The sum of %i and %i is %i!\n", x, y, x + y);
}
这是我收到的错误消息:
This is the error message I get:
jharvard@appliance (~/Dropbox/pset-1): ls
adder.c even-odd.c hello
jharvard@appliance (~/Dropbox/pset-1): clang -o adder adder.c
/tmp/adder-iuV3am.o: In function `main':
adder.c:(.text+0x19): undefined reference to `GetInt'
adder.c:(.text+0x32): undefined reference to `GetInt'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
jharvard@appliance (~/Dropbox/pset-1):
我的猜测是由于某种原因找不到图书馆;没有人有任何想法要做什么才能使所有内容畅通无阻吗?
My guess is it's not finding the library for some reason; does anyone have any ideas what needs to be done to get everything talking?
我搜索了一些其他问题,并参考了使用cs50.c文件的答案,但我认为这些都是试图在自己的计算机上而不是在多合一设备中进行编译的人。
I searched some other question with answers in reference to using a cs50.c file, but I think those were from people trying to compile on their own machines and not in the all-in-one appliance.
推荐答案
告诉编译器通过运行以下任一命令来链接库:
You got to tell the compiler to link in the library by running either
clang -lcs50 -o adder adder.c
或简单地
make adder
因为他们已经为您配置好了。
since they have make configured for you already.
这篇关于CS50库不会链接到CS50设备中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!