参考博客https://blog.csdn.net/u012822903/article/details/62217441
se模式需要注意,使用静态编译,单线程
step 1
新建一个自己的文档
比如说我就新建了/home/zwj/gem-code/hello
文件夹
然后在文件夹中写自己想要测试的程序
vim hellozwj.c
#include <stdio.h>
int main(){
int x,y,count;
x = 3; y = 4;
count = x + y;
printf("today, your lucky number is %d\n",count);
}
vim tips: vim是按i键进入插入编辑模式,按esc退出编辑模式,输入:wq保存并退出,输入:q不保存退出
step 2
静态编译自己的.c文件
gcc -o hellozwj hellozwj.c -static
- -o为指定输出文件的名字,如果不带-o,命令则变为
gcc hellozwj.c
,默认会生成名为a.out的可执行文件 - -static表示静态编译,如果不使用静态编译,那么gcc就会优先使用动态库进行编译,动态编译则会动态链接使用的库文件
- 动态编译和静态编译的区别:动态在程序运行时被链接,静态库直接在编译时所用到的库文件链接进了可执行文件,所以静态编译出来的复杂程序会大很多
step 3
测试自己的.c文件
输入
sudo build/X86/gem5.opt configs/example/se.py -c /home/zwj/gem5-code/hello/hellozwj
不知道自己程序放到哪里的,可以使用pwd
命令查看当前路径
输出结果
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled May 18 2021 21:53:40
gem5 started May 26 2021 18:07:27
gem5 executing on ubuntu, pid 5961
command line: build/X86/gem5.opt configs/example/se.py -c /home/zwj/gem5-code/hello/hellozwj
Global frequency set at 1000000000000 ticks per second
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
0: system.remote_gdb: listening for remote gdb on port 7000
**** REAL SIMULATION ****
info: Entering event queue @ 0. Starting simulation...
warn: readlink() called on '/proc/self/exe' may yield unexpected results in various settings.
Returning '/home/zwj/gem5-code/hello/hellozwj'
info: Increasing stack size by one page.
warn: ignoring syscall access(...)
today, your lucky number is 7
Exiting @ tick 10442000 because exiting with last active thread context
测试完成