Linux development environment configuration experiment

Linux development environment configuration experiment

The purpose of the experiment:
1.1 understand the application development process under the Linux operating system
1.2 master the use of the gun tool chain
1.3 master the gdb debugging skills

Experimental content:
Create a test user, and the password is also test.
After logging in with test, create the src directory, and all source code, intermediate code, and target code are placed in the / home / test / src directory.
Write a simple summation function that can solve the accumulated value from 0 to n, and store it in test2.c.

#include"test.h"
int test(int m)
{
	int sum=a;
	int i;
	for(i=a;i<=m;i++)
	{
		sum+=i;
	}	
	return sum;
}

Write a main function, store it in test1.c, ask to print the welcome message, and enter the value of n, print the summed value (function to call test2.c)

#include<stdio.h>
#include"test.h"
int main()
{
	int n;
	scanf("%d",&n);
	printf("%d",test(n));
	
}

Write a header file, the macro defines some initial values, stored in test.h, for two functions.

#define a 0
int test(int);

Write a Makefile and generate an executable file test.

test:test1.o test2.o
	gcc test1.o test2.o -o test
test1.o:test1.c test.h
	gcc -c test1.c -o test1.o
test2.o:test2.c test.h
	gcc -c test2.c -o test2.o
clean:
	rm -rf *.o test

Next, let's take a look at the screenshot of the running result:
Insert picture description here
Insert picture description here

Published 16 original articles · Like1 · Visits 180

Guess you like

Origin blog.csdn.net/weixin_44931542/article/details/105261865