如何将库添加到“make”中c中的命令
现在我在以下示例中使用它们http://www.paste。 ubuntu.com/576370/ — 不再可用。
我已经将头文件放入 /usr/bin/include
或类似的文件中,当我尝试使用 gcc -o xxx xxx.c
编译我的代码时,它没有不起作用,所以尝试解决这个问题,以下方法有效: http://www.paste.ubuntu .com/576371/ — 不再可用。
现在我想做一些事情来使 'make' 命令像 gcc
那样工作。
我需要做什么?
以下是老话题:
我使用
gcc
命令 编译 C 程序但一段时间后 一段时间我遇到了问题。我需要 编译一个新的头文件并使用 它作为一个图书馆。名为
cs50.h
的头文件。所以做完之后就可以了 使用以下内容进行编译
<前><代码>gcc -o xxx xxx.c -lcs50它有效,但现在我想使用“make” 命令,但我无法让它工作。
它只是不编译头文件 和我编辑之前 gcc 一样的库 它接受 cs50 库。
所以现在我想添加到“make”中 命令如下:
-lcs50
有人可以帮我吗?
This is the header file and its C file:cs50.h
andcs50.c
Now I use them in the following example http://www.paste.ubuntu.com/576370/ — which is no longer available.
I already put the header file in /usr/bin/include
or something like that and when I try to compile my code using gcc -o xxx xxx.c
, it doesn't work, so tried to fix this and the following way worked: http://www.paste.ubuntu.com/576371/ — which is no longer available.
Now I want to do something to make the 'make' command work as the gcc
does.
What do I need to do?
The following was the old topic:
I was using
gcc
command to
compile C programs but after a period
of time I got a problem. I need
to compile a new header file and use
it as a library.The header file called
cs50.h
.so after doing it and it's ok I can
compile using the followinggcc -o xxx xxx.c -lcs50
It works but now I want to use 'make'
command and I can't get it to work.It just don't compile the header file
and library as gcc was before I edit
it to accept the cs50 library.So now I want to add to the 'make'
command the following:-lcs50
Can anyone help me in this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Makefile 顶部附近,添加以下行:
如果您使用 Make 的默认(隐式)构建规则,那么这就是您需要做的全部事情。如果您使用显式规则,则需要将 $(LDLIBS) 添加到显式规则中。
如果没有 Makefile,则 make 使用默认规则,您可以仅创建一个 makefile
,也可以通过在环境中的 LDLIBS 中指定所需的库来告诉 make 链接到某些库。例如,如果您使用的是 sh 派生的 shell(除 csh 或 tcsh 之外的任何 shell),您可以执行以下操作:
如果您使用的是 csh 变体,您可以执行以下操作:
执行以下操作(同样,对于非 csh shell)
或在运行之前 制作。 (对于 csh 变体,请执行 setenv LDLIBS -lcs50)
Near the top of your Makefile, add the line:
If you are using Make's default (implicit) rules for the building, then that is all you need to do. If you are using explicit rules, you will need to add $(LDLIBS) to your explicit rules.
If there is no Makefile, then make is using default rules, and you can either just create a makefile with
or tell make to link with certain libraries by specifying the required libraries in LDLIBS in the environment. For example, if you are using a sh-derived shell (anything other than csh or tcsh) you can do:
If you are using a csh variant, you can do:
or just do (again, for non-csh shells)
before running make. (For csh variants, do setenv LDLIBS -lcs50)
您可以使用下面的“make”命令来链接库并包含头目录,
假设您有 server.cpp 文件要使用 make 命令进行编译,
输出将把编译命令扩展为,
You can use below “make” command to link library and include header directories,
suppose you have server.cpp file to compile using make command,
Output will expand the compilation command as,
您是否忘记了必须告诉 gcc CS50 库位于哪个目录?
Did you forget that you have to tell gcc in what directory the CS50 library is located?