linux中gcc工具使用笔记
来源:互联网 发布:excel导入mysql 编辑:程序博客网 时间:2024/05/01 12:04
1.gcc编译、汇编、链接
实例工程:main.c hello.c init.c hello.h init.h
命令执行:gcc main.c hello.c init.c -o test
<span style="font-size:18px;">main.c</span>
<span style="font-size:18px;">#include <stdio.h>#include <stdlib.h>#include "hello.h"#include "init.h"void aftermain(void){ printf("\n"); printf("<<<<<<<<aftermain>>>>>>>>>>\n"); printf("............................\n"); return;}int main(int argc, char * argv[]){ printf("===========main===========\n"); init(1234); hello(argc,argv); atexit(aftermain); printf("......atexit......\n"); return 0;}</span>
<span style="font-size:18px;">hello.c</span>
<pre name="code" class="cpp"><span style="font-size:18px;">#include <stdio.h>#include "hello.h"int hello(int argc,char* argv[]){ int i; printf("hello world!\n"); for(i=0;i<argc;i++) { printf("argv[%d]=%s\n",i,argv[i]); } return 0;}</span>
init.c
<pre name="code" class="cpp"><span style="font-size:18px;">#include <stdio.h>#include "init.h"const char ro_data[1024]={"This is readonly data"};static char rw_data[1024]={"This is readwrite data"};static char bss_data[1024]={};int init(int number){ printf("the input number is %d \n",number); printf("ro_data:%x,%s \n",(unsigned int)ro_data,ro_data); printf("rw_data:%x,%s \n",(unsigned int)rw_data,rw_data); printf("bss_data:%x,%s \n",(unsigned int)bss_data,bss_data); return number;}~ </span>
hello.h
<pre name="code" class="cpp"><span style="font-size:18px;">#ifndef __HELLO_H__#define __HELLO_H__int hello(int argc,char* argv[]);#endif</span>
<span style="font-size:18px;">init.h</span>
<pre name="code" class="cpp"><span style="font-size:18px;">#ifndef __INIT_H__#define __INIT_H__int init(int number);#endif~ </span>编译,汇编,链接结果是
<span style="font-size:18px;">honker@ubuntu:~/workdir/demo_gcc$ lshello.c hello.h init.c init.h main.c testhonker@ubuntu:~/workdir/demo_gcc$ ./test===========main===========the input number is 1234 ro_data:80487a0,This is readonly data rw_data:804a040,This is readwrite data bss_data:804a460, hello world!argv[0]=./test......atexit......<<<<<<<<aftermain>>>>>>>>>>............................</span>
</pre><pre code_snippet_id="434836" snippet_file_name="blog_20140725_3_3652015" name="code" class="cpp">
</pre><pre code_snippet_id="434836" snippet_file_name="blog_20140725_3_3652015" name="code" class="cpp">
</pre><pre code_snippet_id="434836" snippet_file_name="blog_20140725_3_3652015" name="code" class="cpp"><strong><span style="font-size:18px;"> the introduction of atexit() function</span></strong> #include <stdlib.h> void exit_fn1(void) { printf("Exit function #1 called\n"); } void exit_fn2(void) { printf("Exit function #2 called\n"); } int main(void) { /* post exit function #1 */ atexit(exit_fn1); /* post exit function #2 */ atexit(exit_fn2); return 0; }
<span style="font-size:18px;"></span>
<span style="font-size:18px;"></span>
0 0
- linux中gcc工具使用笔记
- linux工具使用:vi,gcc,gdb,make
- Gcc中使用profile工具优化代码
- 在Keil中使用GCC工具链
- Gcc中使用profile工具优化代码
- arm-linux-gcc 使用笔记1
- 【个人笔记】Ubuntu安装arm-linux-gcc 交叉工具链
- Linux下gcc工具
- Linux开发工具:gcc
- configure中arm-linux-gcc编译器使用
- gcc工具使用
- gcc工具使用
- CentOS 操作系统中制作arm-linux-gcc编译工具链
- arm-linux-gcc交叉工具链的使用
- arm-linux-gcc交叉工具链的安装和使用
- linux c 开发工具gcc gdb的使用:
- windows像linux般使用gcc,make等工具
- arm-linux-gcc交叉工具链的安装和使用
- 关于存储用户密码的思考,bcrypt 和 PBKDF2算法
- 证明函数极限的唯一性(百度知道)
- Maven 项目转 Eclipse
- day2-3
- 2070 Fibbonacci Number
- linux中gcc工具使用笔记
- HDOJ题目2045 不容易系列之(3)—— LELE的RPG难题 (递推)
- http 返回值
- Android研究之游戏开发碰撞检测
- java代码编写基本规范
- JS 正则验证表单
- 摆脱“战略早搏” 切勿掉进大数据陷阱
- CF#258 (Div. 2) A.
- 解决request中文乱码的问题