The second week of the experiment

Test 1-vi test

  1. Each .c file, each .h a file, the file name in the best have their own student number
  2. Vi-enter the code and compile with gcc
  3. K in the Vi using printf find help documentation
  4. Vi editing process screenshot submission to full screen, contains its own student number information

Test 2-gcc test

  1. Pre-code, the compiler, assembler, with the input link vi gcc
  2. Executable files generated have their own student number
  3. Submit pre-compiler, assembler, linker, run the process shots, to full-screen, contains its own student number information

Preprocessing stage: header files and macros, -E allows gcc compiler to stop after the end of the pretreatment process, so you can see the process of pretreatment
general format is: gcc [options] file to compile [options] target file gcc - E hello.c -o hello.i

Compilation phase: gcc code translated into assembly language, using the option -S were only compiled without compilation of the results generated assembly code. gcc -S hello.i -o hello.s
compilation phase: turn .s file into an object file, use the -c option to see the assembler code into binary object code. gcc -c hello.s -o hello.o
the link stage: the default search link to libc.so.6 library among the function call library file that has been achieved.
Run: ./ hello


Test 3-gdb test

  1. Gcc -g compiler code with the input vi
  2. Setting a breakpoint at line main function
  3. In the main function adds an empty cycle, the four cycles for their school, about half of the condition setting a breakpoint number school
  4. Screenshot submit debugging (must contain conditional breakpoints), to full-screen, contains its own student number information
    GDB basic commands are:
    gdb programm (start GDB)
    b set breakpoints (to be set up four kinds of breakpoints: line break point function breakpoints, breakpoint condition, temporary breakpoint)
    rUN starts a program running
    bt print function call stack
    p to see the value
    c to continue the current breakpoint from the breakpoint
    n single step
    s single-step operation
    set breakpoints
    function: B .c file name: name function
    line: rows B
    conditions: number of lines if expression B (e.g.: b 9 if == 12)
    temporary: TB [file name:] line number or function <conditional expression >


Test Test 4 - static library

  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

Static library
static library is a set of object files (.o files) in the archive ((lib + name) .a file); linking phase, select the static library, the suffix ".a", select the dynamic library extension is ".so".

Generate static link library: gcc -c filename .c ar rcsv libxxx.a xxx.o;
use of static library: gcc -o filename filename .c -L -lxxx.


Test 5- shared library

  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
    dynamic libraries
    generated shared library: gcc -fPIC -c xxx.c gcc -shared -o libxxx.so xxx .o;
    use shared libraries:. gcc -o main main.c -L -lxxx
    generated:
    GCC -fPIC -C add.c sub.c mul.c div.c
    GCC -shared -o libmymath.so add.o sub.o mul.o div.o

-shared -o libmymath.so add.c -fpic GCC div.c mul.c sub.c
GCC -o 20,155,227 main.c ./libmymath.so

test-the Makefile. 6
Makefile. 1 above vi editor to write compiled code, compiled out of the target file is testmymath, you can only use explicit rules.

2 Make submission process shots, to full-screen, contains its own student number information

Makefile
source file in a project of countless, according to their type, function modules were placed in several directories. makefile defines a set of rules to specify which files need to be compiled, which files need compiled, which files need to be recompiled, even more complex functions. Its benefits is - "Automation compilation" Once written, only a make command, the whole project fully compiled, which greatly improves the efficiency of software development.

Guess you like

Origin www.cnblogs.com/banpingcu/p/11586941.html