我正在上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,
发布评论
评论(2)
主要是正确的。
-O
不需要生成输出文件,只需要自定义名称即可。 (-o
,下面的名称只能出现在一起)。-LCS50
表示“链接库CS50
”,而不是LCS50
。它将尝试使用几种不同的名称模式找到此文件,例如libcs50.so
(在Linux上),[lib] cs50.dll [.a] .a]
(在Windows上) ,libcs50.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 calledcs50
", notlcs50
. 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.是的。对于-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.