实验2 Linux程序编辑_编译_运行
- 格式:docx
- 大小:15.42 KB
- 文档页数:4
实验二 Linux程序编辑_编译_运行
一、实验目的:
1. 学会编辑软件Vi相关操作。
2. 熟悉GCC的使用方法
二、实验内容:
1. VI编辑hello程序,文件名为hello.c. 编译程序生成可执行代码。
源代码:
#include
int main()
{
printf("hello! This is our embeded world! \n");
return 0;
}
在linux终端输入编译链接命令:
gcc hello.c -o hello
运行执行文件:
./hello
2. Gedit编辑unsgn_pow程序。分别使用静态库和动态库来两种方式。编译程
序生成可执行代码。
Unsgn_pow.c文件源代码:
unsigned long long unsgn_pow(unsigned int x,unsigned int y)
{
unsigned long long res=1;
if(y==0)
{
res=1;
}
else if(y==1)
{
res=x;
}
else
{
res=x*unsgn_pow(x,y-1);
}
return res;
}
Pow_test.c文件源代码:
#include
#include
int main(int argc,char *argv[])
{
unsigned int x,y;
unsigned long long res;
if ((argc<3)||(sscanf(argv[1],"%u",&x)!=1)
||(sscanf(argv[2],"%u",&y))!=1)
{
printf("Usage:pow base exponent\n");
exit(1);
}
res=unsgn_pow(x,y);
printf("%u ^ %u = %u\n",x,y,res);
exit(0);
}
3. 交叉编译hello程序,并在ARM实验板上运行。
(1)编辑源代码。源代码与题目一相同:hello.c
(2)在终端输入编译链接命令:
arm-linux-gcc hello.c -o hello
(3)将hello可执行文件复制到NFS目录下,在实验板的终端输入运行命令:
./hello 将剪贴板中的内容粘贴在光标后 将剪贴板中的内容粘贴在光标前
附:
Vi的使用:
(1)编辑:
新增 (append)
-- a 从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
-- A 从光标所在列最後面的地方开始新增资料。
插 入 (insert)
-- i 从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
-- I 从光标列的第一个非空白字符前面开始插入资料。
开 始 (open)
-- o 在光标所在列下新增一列并进入输入模 式。
-- O 在光标所在列上方新增一列并进入输入模 式。
(2)修改和删除:
• x 删除光标所在字符。
• dd 删除光标所在的列。
• r 修改光标所在字符,r後接著要修正的字符
• R进入取代状态,新增资料会覆改原先资料, 直到按[ESC]回到指令模式下为止。
• s 删除光标所在字符,并进入输入模式。
• S 删除光标所在的列,并进入输入模式。
(3)退出保存:
• <:q>不保存退出
• <:q!>不保存强制性退出
• <:w>保存编辑
• <:w filename>存入文件filename 中
• <:w! filename>强制性存入文件filename 中
• <:wq>(<:x>)保存并退出(shift+zz)
(4)光标移动:
• 移动到当前单词的开始
•
•
•
•
•
•
(5)替换操作:
•
•
•
•
•
•
•
•
复制与粘贴:
• 将光标所在单词拷入剪贴板
•
•
•
•
•