GCC的基本操作
来源:互联网 发布:电脑管家软件管理 编辑:程序博客网 时间:2024/06/05 06:10
查看gcc版本号
gcc -v
指定查找头文件的路径
1. gcc main.c math.c -Wall -I./
cd /1114
mkdir include
mkdir src
touch Makefile
cd src/
touch main.c
touch math.c
touch math.h
vi math.c
int add(int a, int b)
{
return a+b;
}
int sub(int a, int b)
{
return a-b;
}
int dive(int a, int b)
{
return a/b;
}
int mul(int a, int b)
{
return a*b;
}
:wq
vi math.h
#ifndef MATH_H_
#define MATH_H_
int add(int a, int b);
int sub(int a, int b);
int dive(int a, int b);
int mul(int a, int b);
#endif
:wq
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
return 0;
}
:wq
gcc main.c math.c -Wall -I./
./a.out
rm a.out
2. gcc src/main.c src/math.c -I./include
cd /1114/src
mv math.h ../include/
cd ..
tree
gcc src/main.c src/math.c -I./include
./a.out
rm a.out
3. gcc -I./include src/*.c -o app
cd /1114
vi Makefile
all:
gcc -I./include src/*.c -o app
clean:
rm app
:wq
tree
make
ls
./app
make clean
tree
只编译,生成.O文件,不进行链接
gcc -c main.c
gcc -c math.c
cd /1114/src
gcc -c main.c
ls
file main.o
gcc -c math.c
ls
gcc main.0 math.o -o app
./app
cd ..
ls
vi Makefile
all:
gcc -c src/main.c
gcc -c src/math.c
gcc main.o math.o -o app
clean:
rm -f src/*.o
rm -f *.o
rm -f app
make
tree
make clean
tree
rm src/app
tree
make
./app
包含调试信息
gcc main.c math.c -g -o app
cd /1114/src/
ls
gcc main.c math.c -g -o app
gcc main.c math.c -o app1
ls -l
gdb app1
list
quit
gdb app
list
quit
ls -l
查看文件的反汇编
objdump -dSsx app
objdump -dSsx app > file
cd /1114/src
rm app1
ls
objdump -dSsx app
objdump -dSsx app > file
vi file
编译优化,数字越大优化得越多
gcc -O0 *.c -o app1
gcc -O3 *.c -o app2
cd /1114/src
ls
rm app
rm file
gcc -O0 *.c -o app1
gcc -O3 *.c -o app2
ls -l
提示更多警告信息
gcc *.c -Wall
gcc *.c -Wall -I../include
cd /1114/src
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
int c=10;
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
printf("c=%d\n", c);
return 0;
}
:wq
gcc *.c -Wall
gcc *.c -Wall -I../include
编译时定义宏
gcc *.c -Wall -DDEBUG -I../includ
cd /1114/src
vi main.c
#include<stdio.h>
#include <math.h>
#define DEBUG 1
int main(void)
{
int a=6, b=3, c=10;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
#ifdef DEBUG
printf("c=%d\n", c);
#endif
return 0;
}
:wq
gcc *.c -Wall -I../include
./a.out
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3, c=10;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
#ifdef DEBUG
printf("c=%d\n", c);
#endif
return 0;
}
:wq
gcc *.c -Wall -DDEBUG -I../include
./a.out
生成预处理文件
gcc -E main.c
gcc -E main.c > file
cd /1114/src
gcc -E main.c
gcc -E main.c > file
vi file
gcc -v
指定查找头文件的路径
1. gcc main.c math.c -Wall -I./
cd /1114
mkdir include
mkdir src
touch Makefile
cd src/
touch main.c
touch math.c
touch math.h
vi math.c
int add(int a, int b)
{
return a+b;
}
int sub(int a, int b)
{
return a-b;
}
int dive(int a, int b)
{
return a/b;
}
int mul(int a, int b)
{
return a*b;
}
:wq
vi math.h
#ifndef MATH_H_
#define MATH_H_
int add(int a, int b);
int sub(int a, int b);
int dive(int a, int b);
int mul(int a, int b);
#endif
:wq
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
return 0;
}
:wq
gcc main.c math.c -Wall -I./
./a.out
rm a.out
2. gcc src/main.c src/math.c -I./include
cd /1114/src
mv math.h ../include/
cd ..
tree
gcc src/main.c src/math.c -I./include
./a.out
rm a.out
3. gcc -I./include src/*.c -o app
cd /1114
vi Makefile
all:
gcc -I./include src/*.c -o app
clean:
rm app
:wq
tree
make
ls
./app
make clean
tree
只编译,生成.O文件,不进行链接
gcc -c main.c
gcc -c math.c
cd /1114/src
gcc -c main.c
ls
file main.o
gcc -c math.c
ls
gcc main.0 math.o -o app
./app
cd ..
ls
vi Makefile
all:
gcc -c src/main.c
gcc -c src/math.c
gcc main.o math.o -o app
clean:
rm -f src/*.o
rm -f *.o
rm -f app
make
tree
make clean
tree
rm src/app
tree
make
./app
包含调试信息
gcc main.c math.c -g -o app
cd /1114/src/
ls
gcc main.c math.c -g -o app
gcc main.c math.c -o app1
ls -l
gdb app1
list
quit
gdb app
list
quit
ls -l
查看文件的反汇编
objdump -dSsx app
objdump -dSsx app > file
cd /1114/src
rm app1
ls
objdump -dSsx app
objdump -dSsx app > file
vi file
编译优化,数字越大优化得越多
gcc -O0 *.c -o app1
gcc -O3 *.c -o app2
cd /1114/src
ls
rm app
rm file
gcc -O0 *.c -o app1
gcc -O3 *.c -o app2
ls -l
提示更多警告信息
gcc *.c -Wall
gcc *.c -Wall -I../include
cd /1114/src
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
int c=10;
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
printf("c=%d\n", c);
return 0;
}
:wq
gcc *.c -Wall
gcc *.c -Wall -I../include
编译时定义宏
gcc *.c -Wall -DDEBUG -I../includ
cd /1114/src
vi main.c
#include<stdio.h>
#include <math.h>
#define DEBUG 1
int main(void)
{
int a=6, b=3, c=10;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
#ifdef DEBUG
printf("c=%d\n", c);
#endif
return 0;
}
:wq
gcc *.c -Wall -I../include
./a.out
vi main.c
#include<stdio.h>
#include <math.h>
int main(void)
{
int a=6, b=3, c=10;
printf("res=%d\n", add(a, b));
printf("res=%d\n", sub(a, b));
printf("res=%d\n", dive(a, b));
printf("res=%d\n", mul(a, b));
#ifdef DEBUG
printf("c=%d\n", c);
#endif
return 0;
}
:wq
gcc *.c -Wall -DDEBUG -I../include
./a.out
生成预处理文件
gcc -E main.c
gcc -E main.c > file
cd /1114/src
gcc -E main.c
gcc -E main.c > file
vi file
0 0
- gcc的基本操作
- GCC的基本操作
- GCC下的一些基本实用操作
- GCC 编译器的一些基本操作
- gcc 基本操作
- gcc的基本使用方法
- gcc的基本使用
- gcc的基本命令
- GCC的基本用法
- gcc的原子操作
- GCC的原子操作
- GCC 编译器的基本使用
- GCC最基本的用法
- gcc 基本的编译选项
- gcc前端的基本结构
- gcc前端的基本结构
- 1.gcc的基本使用
- Linux的GCC基本用法
- 错误 clang: error: linker command failed with exit code 1 (use -v to see invocation)
- f.lux & redshift
- Ajax随笔
- combobox赋值
- Bootstrap快速上手
- GCC的基本操作
- Android开发:Translucent System Bar 的最佳实践------Android性能分析工具整理汇总
- android键值对保存
- 2015湘潭邀请赛 Yada Number
- iOS开发 证书失效解决办法
- 各种音视频编解码学习详解
- hive根据日期获取星期几的方法
- nanyangoj 7 街区最短路径问题
- Python 连接DBF数据库