cc

编程入门 行业动态 更新时间:2024-10-24 17:33:46

<a href=https://www.elefans.com/category/jswz/34/1768664.html style=cc"/>

cc

在一个文件夹下一共四个文件

function.h

#ifndef __FUNCTION_H__
#define __FUNCTION_H__


void func();
#endif


function.c

#include<stdio.h>
#include "function.h"


void func()
{
    printf("this is function.c");
}


test.c

#include <stdio.h> 
#include "function.h"
void main() { 
   func();
   printf("Hello world!\n");


}

Makefile

default: function.o test.o
cc -o test function.o test.o
#tab 开头
function.o: function.c function.h
cc -c function.c
test.o: test.c function.h
cc -c test.c


执行make操作

root@ubuntu:/var/test# make
cc -c function.c
cc -c test.c
cc -o test function.o test.o


root@ubuntu:/var/test# ll
total 40
drwxr-xr-x  2 root root 4096 Apr  7 17:33 ./
drwxr-xr-x 15 root root 4096 Mar 24 17:44 ../
-rw-r--r--  1 root root   91 Mar 24 17:44 function.c
-rw-r--r--  1 root root   67 Mar 24 17:44 function.h
-rw-r--r--  1 root root 1024 Apr  7 17:33 function.o
-rw-r--r--  1 root root  161 Mar 24 17:52 Makefile
-rwxr-xr-x  1 root root 7377 Apr  7 17:33 test*
-rw-r--r--  1 root root  100 Mar 24 17:44 test.c
-rw-r--r--  1 root root 1052 Apr  7 17:33 test.o


root@ubuntu:/var/test# ./test
this is function.cHello world!

更多推荐

cc

本文发布于:2024-02-12 03:55:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1685790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!