命令行提示命令(想了解其在做什么)

发布于 2025-02-12 10:51:00 字数 503 浏览 0 评论 0 原文

我正在上CS50课,我已经安装了CS50.H. 基于指令我在终端中使用以下命令来编译我简单的程序,只想确保我理解我要终端要做的一切。 行是:

gcc -g hello.c -o hello -lcs50 -lm

我知道以下*:gcc =

  • gcc = c
  • -g =生成源级调试信息
  • hello.c =我们要编译的文件的名称
  • -O =写输出文件
  • hello hello =我们的输出文件名称名称

谁能告诉我-LCS50和-LM是什么?我的猜测是,它在(-lcs50)中呼唤LCS50库LCS50,但这再次是一个猜测,并且想确定。

一切正常工作,没有任何问题

,谢谢

I am doing the CS50 class, I have installed the cs50.h.
Based on the instructions I used the following command in terminal to compile my simple program and just want to make sure I understand everything im asking terminal to do.
Line is:

gcc -g hello.c -o hello -lcs50 -lm

I know the following*: gcc =

  • gcc = gnu compiler for C
  • -g = generate source-level debug information
  • Hello.c = name of the file we want to compile
  • -o = write output file
  • hello = our output file name

Can anyone tell me what -lcs50 and -lm are? My guess is that its calling on the library lcs50 in (-lcs50) but again this is a guess and would like to know for sure.

Everything works as it should with no issues

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饭团 2025-02-19 10:51:00

主要是正确的。

  • -O 不需要生成输出文件,只需要自定义名称即可。 ( -o ,下面的名称只能出现在一起)。

  • -LCS50 表示“链接库 CS50 ”,而不是 LCS50 。它将尝试使用几种不同的名称模式找到此文件,例如 libcs​​50.so (在Linux上), [lib] cs50.dll [.a] .a] (在Windows上) , libcs​​50.a (在两者上),Mac上的其他内容。

  • -lm 链接标准数学库,但我认为您不需要在大多数现代GCC发行版中手动指定它。

Mostly correct.

  • -o is not required to generate the output file, it's only needed to customize the name. (-o and the following name can only appear together).

  • -lcs50 means "link the library called cs50", not lcs50. It will try to find this file using several different name patterns, e.g. libcs50.so (on Linux), [lib]cs50.dll[.a] (on Windows), libcs50.a (on both), something else on Mac.

  • -lm links the standard math library, but I don't think you need to manually specify it on most modern GCC distributions.

残花月 2025-02-19 10:51:00

是的。对于-lm,它是用于数学库,默认情况下不链接。这在

Yes. For -lm, it's for the maths library, which is not linked by default. This is explained well at Why do you need an explicit `-lm` compiler option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文