Linux 4 编译选项和反汇编

笔记:

使用基本的编译选项:
-E(预处理)
-S(编译成汇编语言)
-c(编译成目标代码)
链接成可执行文件;
以及objdump将可执行文件反汇编为汇编语言。

用例:

makefile:

APP_NAME = compileopt
APP_OBJS = compileopt.o
CC = gcc
INC = ./
CFLAG += -g

.PHONY : all

all : $(APP_NAME) prev_compile post_compile

$(APP_NAME) : $(APP_OBJS)
	$(CC) $(CFLAG) $(APP_OBJS) -o $(APP_NAME)
	
compileopt.o : compileopt.s
	$(CC) -c compileopt.s -o compileopt.o

compileopt.s : compileopt.c
	$(CC) -S compileopt.c -o compileopt.s

prev_compile :
	$(CC) -E compileopt.c -o compileopt.i
	
post_compile :
	objdump -s -d $(APP_NAME) > $(APP_NAME).txt
	
.PHONY : clean

clean :
	rm -f *.o *.s *.i *.txt
	rm -f $(APP_NAME) $(APP_OBJS)

源文件:

/* compileopt.c */

#include <stdio.h>
#include <stdlib.h>

void printFunc(int i)
{
	printf("hello world! a+b=%d\n", i);
}

int main()
{
	int a = 1;
	int b = 2;
	
	printf("a+b=%d\n", a + b);
	
	printFunc(a+b);
	
	exit(0);
}

猜你喜欢

转载自blog.csdn.net/zzj244392657/article/details/92555051