Linux makefile问题怎么解决

发布时间:2021-12-24 14:03:34 作者:iii
来源:亿速云 阅读:143

这篇文章主要讲解了“Linux makefile问题怎么解决”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux makefile问题怎么解决”吧!

将各个模块的关系写进makefile,并且写明了编译命令,这样,当有模块的源代码进行修改后,就可以通过使用make命令运行makefile文件就可以进行涉及模块修改的所有模块的重新编译,其他模块就不用管了。

makefile文件的写法:

目标, 组件
规则

例如 有下面5个文件:

/* main.c */
#include "mytool1.h"
#include "mytool2.h"
int main(int argc,char **argv)
{
mytool1_print("hello");
mytool2_print("hello");
}
/* mytool1.h */
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
void mytool1_print(char *print_str);
#endif
/* mytool1.c */
#include "mytool1.h"
void mytool1_print(char *print_str)
{
printf("This is mytool1 print %s\n",print_str);
}
/* mytool2.h */
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
void mytool2_print(char *print_str);
#endif
/* mytool2.c */
#include "mytool2.h"
void mytool2_print(char *print_str)
{
printf("This is mytool2 print %s\n",print_str);
}

可以这样进行编译以便运行main这个可执行文件

gcc -c main.c (生成main.o)
gcc -c mytool1.c (生成mytool1.0)
gcc -c mytool2.c (生成mytool2.0)
gcc -o main main.o mytool1.o mytool2.o (生成main)

也可以这样写makefile文件

main main.o mytool.o mytool2.o
gcc -0 $@ $^
main.0 main.c mytool1.h mytool2.h
gcc -c $<
mytool1.0 mytool1.c mytool1.h
gcc -c $<(或者是mytool.c)
mytool2.0 mytool2.c mytool2.h
gcc -c $<(或者是mytool2.c)

通过make命令可以运行该文件,也就是进行编译了。

Linux上有很多库,c语言编写的各种库的总称为libc,glibc为libc的一个子集,由gnu提供,内核提供的系统函数和系统调用是不包括在libc中。

Linux系统默认会安装glibc

glibc中

常用库gcc会自动去查找,不予理会。

在/lib, /usr/lib, /usr/local/lib 在这三个路径下面有一些标准库,只需-l+库名 可以不必要指定路径。其他库必须在用gcc时用-L+具体的路径。通过本文你就能全面了解Linux makefile。

感谢各位的阅读,以上就是“Linux makefile问题怎么解决”的内容了,经过本文的学习后,相信大家对Linux makefile问题怎么解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. 如何解决linux编译kernel和svn版本冲突问题
  2. 如何在Android系统中添加Linux驱动

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux makefile

上一篇:Kubernetes架构的问题有哪些

下一篇:linux中如何删除用户组

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》