c s下linux 操作系统,Linux 操作系统

Linux Qiu_jn@163.net

6 LinuxCLinuxCgccmake

6.1 LinuxC C UNIX C C UNIX 89ANSI ANSI C C ANSI C C C 15 I/O 80 C C++ Linux C GNU C (gcc), ,

6.2 gcc1 Linux gccgcc GNU C C++ gcc CC++ Object C gcc C C++ C gcc main.c factorial.c /*-- factorial.h --*/ #include #include int factorial (int n) { if (n

6.2 gcc2 $ gcc -o factorial main.c factorial.h $ ./factorial 5 Factorial of 5 is 120. gccCC++gcca.outgccgcc.cC.a .C.cc.cxx C++ .h .i C .iiC++ .mObjective-C .o .s .S gcc C++ C++ g++ C++ gcc //hello.C#include void main (void) { cout

6.3 gcc gccCgccC(Preprocessing)(Compilation)(Assembly)(Linking) gcccpp(include)(define) cc1.o as.S.s.o gccld

6.4 Linux1 (static libraries).aELF ar , file1.ofile2.omy_library.a ar rcs my_library.a file1.o file2.o ranlib

6.4 Linux2(shared libraries)sonamesonamelib.so ldconfigldconfigsoname/etc/ld.so.cache (a.ob.o)a.ob.o

gcc -fPIC -g -c -Wall a.cgcc -fPIC -g -c -Wall b.cgcc -shared -Wl,-soname,liblusterstuff.so.1 -o liblusterstuff.so.1.0.1 a.o b.o -lc -fPIC -gWall

6.4 Linux3a. /lib /usr/lib /usr/i486-linux-libc5/liblibc5 /usr/X11R6/libX11R6 /usr/local/lib

b. /usr/include /usr/local/include

c./etc/ld.so.conf ldconfig ldd

6.5 gcc 1 gcc gcc [options] [filenames] options -c.c.o -o output_filenameoutput_filenamegcca.out -g(GNUgdb) -O -O2-O-O3 -O2 inline -I dirnamedirname

6.5 gcc 2-L dirnamedirname -l namelibname.a-L-l mlibm.a-ansi ANSI C GNU C -D MACRO 1 MACRO -D MACRO=DEFN DEFN MACRO -E C -m486 486 -O0 -shared -static -U MACRO MACRO -w -Wall -S gcc C

6.5 gcc 31test.c $gcc test.c a.out 2testmain.c testsub.ctest $gcc testmain.c testsub.c -lm -o test -lmlibm.a

gcc egcsegcsgccc++

6.6 make 1 make make makefile makefile GNU make makefile GNUmakefile makefile Makefile 6.6.1 GNU make

6.6 make 2 UNIXmakefile makfile makefile make makefile $ make -f Makefile.debug 1makefile prog:prog1.o prog2.o gcc prog1.o prog2.o -o prog prog1.o:prog1.c lib.h gcc -c -I. -o prog1.o prog1.c prog2.o:prog2.c gcc -c prog2.c

6.6 make 3 makefile make C++ test.C test.h test.o test.C test.h g++ test.o makefile # This makefile just is a example. test.o: test.C test.h g++ -c -g test.C test.o test.C test.h test.C test.h make test.omake Shell 6.6.2 makefile

6.6 make 4 GNU make # Define macros for name of compiler CC = gcc# Define a macr o for the CC flags CCFLAGS = -D_DEBUG -g -m486 # A rule for building a object file test.o: test.c test.h $(CC) -c $(CCFLAGS) test.c

CC CCFLAGS make GNU make UNIX make makefile $ $(CC) $(CCFLAGS) 6.6.3 makefile makefile make target makefile clean clean: rm -f *.o make clean rm -f *.o

6.6 make 5 GNU make , GNU make : $* $+ $< $? $@ $^ $% mytarget.so(image.o) $@ mytarget.so $% image.o AR ar ARFLAGS AS as ASFLAGS CC C cc CFLAGS C CPP C $(CC) -E CPPFLAGS C CXX C++ g++ CXXFLAGS C++ FC FORTRAN f77 FFLAGS FORTRAN 6.6.4 GNU make

6.6 make 6 make make make -f mymakefile make makefile GNUmakefilemakefile Makefile GNU make GNU make -C DIR makefile DIR -f FILE FILE makefile -h make -i -I DIR makefile -n -p make -s -w makefile -W FILE FILE 6.6.5 make

6.7 gdb gcc 1 GNU gdb X Window gdb xxgdbgdb gdb -g makefile CFLAGS CFLAGS = -g gdb gdb progname gdb help aliases breakpoints data files internals running stack statu tracepoints 6.7.1 gdb

6.7 gdb gcc 2break NUM bt clear clear FILENAME:NUM continue display EXPR file FILE help NAME info break info files info func info local info prog info var kill list make gdb make next print EXPR EXPR 6.7.2 gdb

6.7 gdb gcc 3/* C */ #include #include static char buff [256]; static char* string; int main () { printf ("Please input a string: "); gets (string); printf ("\nYour string is: %s\n", string); } string Segment Fault $ gcc -o test -g test.c $ ./test Please input a string: asfd Segmentation fault (core dumped) gdb 1 gdb bugging bugging 2 bugging 3 where 4 list gets 5 gets string print string 6 gdb string 11 7 11 set variable string 8 6.7.3 gdb

6.8 1 http://www.kernel.org/pub/linux/kernel linux-x.y.z.tar.gzlinux-x.y.z.tar.bz2 Linux "patch-x.y.z.gz" "patch-x.y.z.bz2" 6.8.1 6.8.2 kernel.org cd /usr/src"linux""linux.old /usr/src tar xzvf /path/to/my/kernel-x.y.z.tar.gz cat /path/to/my/kernel-x.y.z.tar.bz2 | bzip2 -d | tar xvf linux : 50

6.8 2 ()() /usr/src/linux make config make menuconfig make xconfig make menuconfig make xconfig X-Window GUI "make menuconfig" "< >" ("")("")

6.8.3

6.8 3make dep; make clean (dependency) /usr/src/linux make dep; make clean make bzImage make bzImage /usr/src/linux/arch/i386/boot(x86 PC ) bzImage bzImage -- bzImage make modules; make modules_install /usr/lib/

lilo

6.8.4

6.8 4 LILO LILO LILO /usr/src/linux/arch/i386/boot/bzImage /boot /boot/vmlinuz2 lilo.conf lilo.conf boot=/dev/hda delay=20 vga=normal root=/dev/hda1 read-only image=/boot/vmlinuz2 label=linux image=/boot/vmlinuz label=oldlinux root "lilo" "lilo" lilo

6.8.4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值