Compilingunder Linux<br />
Whatyouneed…<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking...
[COMMAND GCC] GNU COMPILER COLLECTION<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br...
[COMMAND GCC]-o option: file.cfile.exe<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<...
[COMMAND GCC]Compiles multiple sources<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<b...
[COMMAND GCC]-c option to createobjects<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<...
[COMMAND GCC]Linkwith the libraries<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br /...
[COMMAND GCC]Linkingorder<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option...
[COMMAND GCC]-Wall option<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option...
[COMMAND MAKE]Functionality<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c opti...
Makefile
Relations between the files
Dependencies
Make: brain</li></li></ul><li>[COMMAND MAKE]Working<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multip...
Creates B & D
Determineslibraries and gcc arguments for B & D
Compiles
Advanced feature: update of files depending on other files</li></li></ul><li>[MAKEFILE] MINIMAL MAKEFILE<br />COMPILING UN...
[MAKEFILE] EXAMPLE<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />L...
Upcoming SlideShare
Loading in...5
×

Compiling Under Linux

979

Published on

Compiling under Linux.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
979
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Compiling Under Linux

  1. 1. Compilingunder Linux<br />
  2. 2. Whatyouneed…<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />2<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  3. 3. [COMMAND GCC] GNU COMPILER COLLECTION<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />3<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  4. 4. [COMMAND GCC]-o option: file.cfile.exe<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />4<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  5. 5. [COMMAND GCC]Compiles multiple sources<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />5<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />$ gcc -Wall main.chello_fn.c -o newhello<br />$ cat hello.h<br />void hello (const char * name);<br />
  6. 6. [COMMAND GCC]-c option to createobjects<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />6<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />$ gcc -Wall -c main.c main.o<br />$ gcc -Wall -c hello_fn.c hello_fn.o<br />$ gccmain.ohello_fn.o -o hello  hello.exe<br />Linking step gcc uses the linkerld<br />ld = a separate program.<br />
  7. 7. [COMMAND GCC]Linkwith the libraries<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />7<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />Default library: libc.a<br />___<br />#include <math.h> <br />#include <stdio.h> <br />intmain (void) {<br />double x = sqrt (2.0); printf ("The square root of 2.0 is %f ", x); return 0;} <br />___<br />$ gcc -Wall calc.c -o calc<br />/tmp/ccbR6Ojm.o: In function `main': <br />/tmp/ccbR6Ojm.o(.text+0x19): undefinedreference to `sqrt' <br />___<br />$ gcc -Wall calc.c/usr/lib/libm.a-o calc<br />___<br />$ ./calc<br />The square root of 2.0 is 1.414214<br />___<br />$ gcc -Wall calc.c-lm -o calc<br />
  8. 8. [COMMAND GCC]Linkingorder<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />8<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />$ gcc -Wall calc.c-lm -o calc (correct order) <br />$ gcc-Wall -lm calc.c -o calc (incorrect order) <br />main.o: In function `main': <br />main.o(.text+0xf): undefinedreference to `sqrt' <br />
  9. 9. [COMMAND GCC]-Wall option<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />9<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />#include <stdio.h> <br />intmain (void)<br />{ <br />double x = pow (2.0, 3.0); <br />printf("Two cubed is %f ", x); <br />return 0; <br />} <br />___<br />$ gccbadpow.c -lm <br />$ ./a.out<br />Two cubed is 2.851120 (incorrect result, should be 8)<br />___<br />$ gcc -Wall badpow.c -lm <br />badpow.c: In function `main': <br />badpow.c:6: warning: implicitdeclaration of <br />function`pow' <br />
  10. 10. [COMMAND MAKE]Functionality<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />10<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br /><ul><li>Program: lot of filesgcceach time?
  11. 11. Makefile
  12. 12. Relations between the files
  13. 13. Dependencies
  14. 14. Make: brain</li></li></ul><li>[COMMAND MAKE]Working<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />11<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br /><ul><li>Make A (dates)
  15. 15. Creates B & D
  16. 16. Determineslibraries and gcc arguments for B & D
  17. 17. Compiles
  18. 18. Advanced feature: update of files depending on other files</li></li></ul><li>[MAKEFILE] MINIMAL MAKEFILE<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />12<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />$ makehello <br />target: dependances<br /><tab> commands<br />
  19. 19. [MAKEFILE] EXAMPLE<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />13<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  20. 20. [MAKEFILE] RICH MAKEFILE<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />14<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  21. 21. [MAKEFILE]MACROS FOR FLEXIBILITY<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />15<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  22. 22. [MAKEFILE]DIRECTIVES<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />16<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />
  23. 23. [DEBUG]Working<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />17<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />gdb<br />
  24. 24. [DEBUG]Features<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />18<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br /> Eye "inside" the program.<br />GDB can: <br /><ul><li>Start the program.
  25. 25. Conditionally stop the program.
  26. 26. Determine the cause of stop.
  27. 27. Change things in your program in order to test the effect</li></li></ul><li>[DEBUG]Example<br />COMPILING UNDER LINUX<br />COMMAND GCC<br />-o option<br />Multiples sources<br />-c option<br />Linking with Libraries<br />-wall option<br />COMMAND MAKE<br />Functionality<br />Working<br />MAKEFILE<br />Minimal makefile<br />Example<br />Rich makefile<br />Macros<br />Directives<br />DEBUG<br />Working<br />Features<br />Example<br />19<br />Pierre Masure | EMBEDDED LINUX: COMPILING UNDER LINUX<br />$ gcc -g prog.c -o prog // compiling with –g<br />$ gdb progcore // starting the GDB<br />(gdb) b funct // inserts a breakpoint<br />(gdb) b prog.c:134 <br />(gdb) r // run the debug<br />(gdb) n // next instruction<br />1350 if (Array1[i]!=i)<br />(gdb) print i <br />(gdb) l funct // source of funct<br />(gdb) c // continue<br />(gdb) n X // steps of n instructions<br />[…] // error<br />(gdb) bt // bactrace (to pile of function call) <br /> [where/up/down]<br />(gdb) l prog.c:funct // source of funct<br />q // quit<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×