首页 > 解决方案 > 当我包含 cs50 库时使用 make 编译时出现问题?

问题描述

我已经 在Ubuntu 20.04中安装了CS50 库 此代码只是为了查看它是否可以正常工作 它可以正常使用 clang 但是使用 make 它不会自动链接库所以我收到此错误 - 我正在使用 Visual Studio 代码

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

int main(void)
{
    string d = get_string("what is your name: ");
    printf("Hello, %s\n ",d);
}

输出

mohamed@mohamed-Latitude-E5470:~/Downloads/projects$ clang hello.c -o hello -lcs50
mohamed@mohamed-Latitude-E5470:~/Downloads/projects$ make hello
cc     hello.c   -o hello
/usr/bin/ld: /tmp/ccJDbREo.o: in function `main':
hello.c:(.text+0x1e): undefined reference to `get_string'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: hello] Error 1

使用make时如何使其自动链接库

标签: ubuntumakefileclangcs50

解决方案


推荐阅读