GCC直接编译代码

参考文章:

http://www.linuxidc.com/Linux/2011-01/31227.htm


1.单个文件编译

编写源文件hello.c

编译:gcc hello.c

生成a.out


指定生成文件名:gcc -o test  hello.c

生成test


2.编译成目标文件

编译:gcc  -c  hello.c

生成:hello.o

指定生成文件名:gcc -c  -o test.o hello.c

编译:gcc -c file1.c file2.c file3.c

生成:file1.o file2.o  file3.o


3.多文件编译

编写计算字符串长度函数string.c如下:

#define ENDSTRING '\0'
int StrLen(char *string)
{
 int len=0;
 while(*string++ != ENDSTRING)
 len++;
 return len;
}

编写主函数main.c 如下:

#include<stdio.h>

extern int StrLen(char* str);

int mian(void)

{

char src[]="Hello Dymatic";
printf("string length is: %d\n",StrLen(src));
return 0;
}

编译:gcc -o test  string.c main.c

生成:test

执行结果:string length is: 13

也可先生成目标文件:gcc -c string.c main.c

编译:gcc -o test string.o main.o


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值