2019-2020-1 20,199,329 second week of testing (environment: ubuntu64 bit)
experiment one
0. Each .c file, each .h a file, the file name in the best have their own student number
1. Vi enter the code and compile with gcc
2. Use K in the Vi printf find help documentation
3. Submit a screenshot vi editing process to full screen, contains its own student number information
solution
1. Create six empty file, the picture in each function writes a blank file separately, and modify the file name, but the first file name suffix .h, other file extensions are .c.
2. Start a terminal, type gcc -c *.c
, folder all the .c files are compiled to obtain a .o file
3. Enter the terminal folder vim main.c
, hit enter again shows the editing interface function. The second step to move the cursor to the statement printf
, and then enter the uppercase K display help document
The second experiment
1. The pre-code, the compiler, assembler, with the input link vi gcc
2. Generate executable file have their own student number
3. Submit preprocessing, compiler, assembler, linker, run the process shots, to full-screen, contains its own student number information
solution
1. Open the terminal in the folder are sequentially input gcc -E main.c -o main.i
, gcc -S main.i -o main.s
, gcc -c main.s -o main.o
generated main.i
, main.s
, main.o
plus the original main.c
total of four documents, while add.c
, sub.c
, mul.c
, div.c
is also operated.
2. In a terminal gcc -o 20199329 *.o
generation to learn the name of the executable file number, and enter ./20199329
the program.
Third experiment
1. gcc -g compiler code is entered vi
2. Set a line breakpoint in the main function
3. In the main function to increase an empty cycle, the four cycles for their school, about half of the condition setting a breakpoint number school
3. Submit the commissioning process shots (must contain conditional breakpoints), to full-screen, contains its own student number information
solution
1. Open the input terminal gcc -g *.c -o test
to produce an executable file gdb test ,. input gdb test
into the gdb debug mode, then the contents of the input test file displayed l, the test is written in a for(i=0;i<5313;i++)
dry cycle is used to detect the breakpoint. In gdb debugger window enter b main
the main function of the first row set a breakpoint, then enter b 13 if i==2600
i.e. another breakpoint at the 2600th cycle. Then enter the info break
display breakpoint information, then enter r to run the program, a breakpoint is encountered will display the contents of the breakpoint, because the cycle is set to null, the loop at the breakpoint content does not appear. If the design of a counter within the recirculation loop at the breakpoint within the count will appear as 2600.
Experiment 4
1. In addition to main.c, the other four modules (add.c sub.c mul.c div.c) do not want the source code to others, how to make a mymath.a static library? main.c how to use mymath.a?
2. Submit static library generation process and calls shots (must contain conditional breakpoints), to full-screen, contains its own student number information
solution
1. First input ar -cr mymath.a add.o sub.o mul.o div.o
to create a static library and the add.o
, sub.o
, mul.o
, div.o
copied into this static library, after an experiment similar to the operation of the cycle breakpoints.
Experiment 5
1. In addition to main.c, the other four modules (add.c sub.c mul.c div.c) do not want the source code to others, how to make a mymath.so shared library? main.c how to use mymath.so?
2. Submit shared library and call the procedure screenshots (must contain conditional breakpoints), to full-screen, contains its own student number information
solution
1. In the input terminal gcc -shared -fpic -o mymath.so add.c sub.c mul.c div.c
, to build a four c shared library files. Then enter gcc -o prog2 main.c ./mymath.so
to generate an executable file prog2. The last direct input ./prog2
will be able to run the file.
Sixth experiment
1. vi editor to write makefile compile the above code, compiled object file testmymath, you can only use explicit rules.
2. Make submission process shots, to full-screen, contains its own student number information
solution
1. First vim Makefile written, and then enter the make, run the generated object files in the shell:
Questions Myod
1 review c file processing
2 write myod.c achieved under Linux od -tx -tc XXX function with myod XXX
main separate from other, making static and dynamic libraries
Writing the Makefile
5 to submit the results of the test code and run shots, shots submit debugging process, to full-screen, contains its own student number information
6 published a blog in blog Park, problems encountered and solutions focus on writing process
solution
1. Code implementation:
2. Implementation: ascii value output is converted to% d% c output an output, the output is a hexadecimal% c% x output into output.
3. static library produced in the following figure:
4. FIG dynamic library prepared as follows:
5.makefile document production as shown below:
(1) First, the input vim Makefile, edit the following:
(2) Next, enter the following command file:
September 25, 2019