UPEvent: GCC and Makefiles

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
start streaming it's all yours hello everyone I'm Frederick I'm Rob Dobrowski and we're from U P which is WPI is chapter of U P it's a pure sine of Phi Epsilon Pi Upsilon yes so today our presentation will be on GCC and make files and Fred's gonna start us off okay can you hear me all right right here okay so what we're gonna go over today we're gonna go talk about what GCC is the compilation process some useful flags for GCC that you should probably know if you're gonna be doing anything related to CS with GCC then Rob is gonna talk about make files and what we use make files for and how to use them okay so what is GCC it stands for the GNU Compiler collection it's a compiler and the linker it's receipt gene plus plus is for C++ there are multiple other versions for other languages I believe Fortran is supported a DES is supported basically if it's a programming language out there GCC supports it in some form there's even a version of GCC for Java so GCC supports just about everything some other compilers you may be familiar with LLVM clang is a set is LLVM clang is the actual compiler LLVM does other stuff and Java C is another one so if you ever use Java Java C is what is what Java uses to compile all of your programs so the compilation process is a very simple four-step process so we start with pre-processing then we move that's when we take C and we turn it and we do some well we'll get into that then we move to compilation then we move to assembly and then finally we move to linking and at the end is produced a executable file in what for whatever you're building it on so for Linux it produces in one form for Windows it produces in another but at the end you have something that you can run on your target computer hopefully okay so let's start with the first step pre-processing what does it do it expands the header file so if I include printf it expands all of the definitions inside of printf dot error standard IOH okay it strips out all your comments it expands all macros which are anything that you use with pound define and then file extension is generally dot I you don't really ever see these files but they do exist and then we can look at the output of this with the dash 'flag on GCC so move over to putty this is a why did you stop I did not press stop oh that got me again uh okay so this is a pretty simple can everybody see that okay do we need to dim the lights good okay so this is a pretty simple hello world program we start by including two SQ standard IOH so we have access to the printf function then we do a pound to find this is the traditional pound to find that you're familiar with it defines hello world to be the text hello world newline then we define a macro this macro takes two arguments it's called average and what it will do is it will average these two arguments so a plus B cast it to a float / - pretty simple next we move to preprocessor if deaths and what this allows you to do the preprocessor language in itself is powerful you can do different things with the preprocessor language so here I'm saying if there is a preprocessor variable called debug which is different than any any variable you declare in your regular code but if I've defined debug much like I've defined hello world here then debug print is going to be equal to this statement this statement is called the very attic macro it allows what it allows me to do is it allows me to take create a macro which takes multiple arguments so the syntax for that is dot dot dot and then to use all of those arguments here we say printf var X so what you might want to use this for is for example in this case what debug print is going to do is it's going to take some number of arguments so a normal printf statement which we know takes some number of arguments and then it's going to put them inside of a printf statement which then will work just as you've normed just as you're used to okay and then again we use some preprocessor definitions to say else if we're not in debug mode then we don't want to do anything so we've just defined debug print to be a very active macro which expands to nothing literally nothing it doesn't it it just replaces the text with blank and then we end our preprocessor s so anybody have any questions on that cool and then Maine is pretty simple we print hello world we print the average of one and two with our macro then if we can use we can use the if deaths anywhere in the entire program so we can do if def debug right inside the main line of code and just create different different program flow and then finally we use the we use our very attic macro okay so now okay so what we said we said the the - f flag so don't give me - e flag GCC - e - oh hello world dot I and then we want to compile hello world let's see okay so let's take a look at that file hello world I first we see a whole bunch of stuff okay these what these are is the expansion of standard IOH there is a lot of stuff in standard IOH as we can see here and it's all expanded and it's put into this file it's into this dot dot I file and here we can see some standard i/o stuff some more standard i/o stuff some more standard i/o stuff still more Gilmore here's some of the file IO stuff so if you're if you're doing stuff with file operations F open I've closed a flush here's printf then that's the definition of printf so it expands that and puts that in this file some scan at scanf is right here okay let's skip to the end okay and then here is our actual code so 95% of this is stuff that we haven't written so if we take a look how well this will actually work because it's a small screen so we can see what the preprocessor does with these macros is it literally does a text replace so here where I had hello world it's now put that in there all right so just straight up string replace done next average of one and two is let's go over again just a straight string replace except instead of a and B we now have one in two and then we're not in debugging mode so everything else vanishes and finally there's just a just a semicolon there because there's a semicolon on the end of here which is not part of the macro okay so we have a you have just a stray semicolon air which is which is perfectly fine so that's the preprocessor at this point this file is now ready to be compiled and turned into actual assembly language things that we can actually do with it so again the preprocessor expands all your headers so if we if we include our own header all the definitions all the type depths would be in there and it strips out all your comments expands the macros and it's the output is a dot I file next is compilation this takes that file that we just looked at and translates it into assembly language into literal assembly code and the type of assembly code is dependent on the machine that you're using so any of your modern computers today your desktop computers will be using x86 or x---eighty six underscore 64 generally referred to as either 32 or 64-bit the file extension is generally dot s and then we can look at this with output with the US flag so if I go back to my shell and I want HelloWorld dot yes okay this is assembly language if you've taken but I think it's 2011 with Professor Lauer you'll be familiar with x86 assembly if not this is the language that your computer runs this is transforming C into something your computer can almost understand it's still human readable at this point that's the next step we'll turn it into something that we can't even understand but here we can see this is our this is our function so we have main here and then all of these assembly language instructions are our actual program so it takes our program and then it actually turns it into things and we can see here it's doing a print here it's calling printf it hasn't done any linking yet so it doesn't know the offset of printf it doesn't know we're in printf memory is here we're doing a printf as well and all sorts of fun things like that so another thing what about all of our debug stuff right we have we have deep if we look back at hello world let's see we have this line of debug statement here and then we have this whole debug print and we haven't used either of those yet because debug is not defined correct so we can define things in GCC with the - D flag so like that so I've now defined debug first let's take a look at the at the preprocessor output I'm gonna call it hello lovely bug hi okay all this stuff is the same the only difference is come here this time instead of I'm not in debugging mode we see I've enabled debugging mode and here it's replaced my debug print with my very attic macro pretty straightforward ok the next step of these of the compilation process is assembling so we've moved through preprocessor we've just compiled to assembly language now we have to take the assembly language and turn it into something the machine can understand currently it's readable to us it's filled with the this file is filled with characters that are asking that we can understand that makes sense to us if they don't make any sense to the computer and it's pretty it's a pretty big file computers don't need as long words as us in order to understand the same thing so it takes human readable assembly code and turns it into what's called byte code which is essentially a whole bunch of they're essentially a bunch of numbers it looks like a bunch of gibberish when you look at it and I'll show you in a second but it's in hex if you you can open up any executable and a hex editor and you can see memory addresses and you can see the the values in each section of the program and often what you can do is you can scroll down to some of the sections some of the sections are still in ASCII so we have a string section in binary files and those are still in ASCII because those still need to be displayed to us because printing a whole bunch of eight characters isn't going to help you when you're trying to print something and so these are non human readable there are quote unquote holes in each of these files so we haven't done the process of linking yet so we haven't gone out and filled in the definition for printf printf is still just a call into nothingness it doesn't exist yet the processor has no idea about it these are called object files with the the assembled files or Kol object files we can see them with the - sea flag and these are the these are the targets when later when he's talking about make this is what you what you get out when you use the - sea flag in your targets so I already have a precompiled version oh that is a assembled file basically this is just a whole bunch of assembly code it looks like gibberish with the exception of here we can see my hello world text here we can see my average here here this is the string formatter for print F so we see the % F here and here we see my not in debugging mode text and then this what GCC will do is it will also append the version of GCC that we're using which in this case is version 4.4 point seven that's the compiled 8 2012 Oh 313 and it was it's the Red Hat version so it's four point four point seven dash for Red Hat Linux compiled by Red Hat and then here we see some other fun assembly stuff and then these are function function calls so here's the name of the file that was compiled from and then here's the name of mark functions so we have printf which uses puts and then we have main so we've gone from this to that which makes no sense we can't run this yet printf doesn't exist it doesn't know how to use it this is a hole so to speak so the final step of this process is called linking linking takes all of your disappered files so in this case it's going to go fine it's going to go use the library that's pre-installed on the system to find the definition for printf and that's installed on just about every Linux system it's called standard library GG the GNU standard library so it takes all of these separate audio files and it links them together into one file so all of your definitions are there all of your code is there and the hopefully provided you who compiled correctly your program will actually run the produced file is called an executable or a binary and it's no separate flag this this is the final output just GCC name of the file - OH name of the output and so we can accept files from any step on the process so I can feed it a dot I file I can feed it a dot s file or I can feed it a dot o file as long as it's in a format from GCC at some part of the process so it can be straight C or anything along the line so world hello world dot see and if I run hello world it says hello world and then here's the output of our macro and then that's the statement we defined if we're not in debug mode so we can also catch Oh a little worldly bug and here's the output of our very attic macro there's our debugging if def yeah and there's the rest of our program output so that is what GCC does at a very high level well not very hot but high level there any questions before we move on to common GCC slides if that's a really quiet like really really quiet okay so GCC has many many many many many many many many many many many many many many flags many we go take a look jump around on me seriously just cooperate please now you tell me justice go do it thank you okay here are just some of the options that GCC has notice the scroll bar notice the size of the scroll bar on the side you're not gonna need to work with ninety-five 99.95% of these options thankfully but there are a lot of them so here the some of the common ones that you should know about okay most options will read as type option so it's for an example - wall stands for - that's the I'm invoking a flag warnings W is warnings all all warnings so - wall is all warnings make sense so there are some specific types of language of flags you have general language options you have warnings options optimization options machine-dependent options so if you're compiling for x86 vs. arm like your phone versus msp430 if you if you've done embedded these are these are options that are specific to each of these different platforms we have debugging options we have copulation steps options and these are the these are the ones I just went over and then there are also other because there are so many options that can't all fit possibly fit under these types so language options most of them have either the - F or the - W prefix excuse me some of them have no prefix some of the most common ones that you would use have no prefix so for example s - s TD is equal to standard name so that's that's the language level so si has had multiple revisions over the years there's a standard 89 standard 90 C 99 so if you wanted to use any particular language you would do - STD equals c 99 for example c 99 gives you allowing you to declare int the the inside of a for loop you can declare that variable as part of that for statement whereas previous to that you had to declare outside of the for statement - ANSI forces compatibility with ISO C 90 which is the official ISO some some people need it you're not likely to ever need it unless you're working in a lot unless you're working in an environment that requires very specific very specific standards of culpability and warning options most of them have the - W prefix a few have - F and again a few have no prefix so some common warning options that you've seen - wall if you're if you're in if you took systems with professor Lauer heap forces you - you have - wall and - W error which says turn on all warnings that's - wall and - W error is treat all warnings as errors meaning they will fail compilation so if you get a if you get a warning for unn unchecked cast it will fail because you have - w error and then - w pedantic is used in combination with - auntie - for strict compliance with ISO C most other warning options you're not going to turn on explicitly the - W all will turn on most of the rest of the warning options on itself because it's - W all there are a few that turn off warnings for specific things generally you don't want to use those because if it's a warning it there's likely a warning for a reason but they do exist optimization options GCC is capable of taking your code and optimizing the heck out of it it is going to produce the most optimized version of your code that it possibly can generally speaking you don't have to worry about writing your code too heavily optimized you do have to think about it but a lot of the specific ordering of things you often don't have to think about because GCC will take a look at it and will say this is equivalent to that that is faster I'm choosing that GCC we'll be able to get just about everything regardless of whether or not you pick it up on your own most have the dash F prefix but the important ones have the dash o prefix so o - o - o 1 o 2 O 3 - go fast - og and - OS these are the various optimization levels oh woah-oh is basically minimum optimizations oh one is basically the same thing they're they're equivalent - OH - is slightly more optimizations - oh three turns on most optimizations that are guarantee well not guaranteed but most likely will not cause your code to have issues - oh fast turns on a whole bunch of fun options that could make your code go pass go fast depending on the computer that you're on or it could make your code break depending on the computer that you're on one of my favorite ones that it turns on is - F unsafe math so depending on the specific architecture of your processor it can actually vary between different Intel processors it might make it faster or it might break your math one of the - it's fine - og is treat everything no optimizations at all as close to original as possibly make it and then you know the rest is just even more optimization levels these these manage most of the rest of the optimization flags are not again you're not generally just like - warning all you're not really going to need to use any specific optimizations flex with the exception of some of the safety ones so for example - you have stack protector and - have stack protector all - jeff stack protector strong these are stack protectors which help prevent your code from being from causing a buffer overflow and allowing malicious hacker to get access to anybody else's computer generally you want to turn these on because you don't want your code to be the reason that somebody else's computer gets hacked that's bad that's very bad so it helps to prevent buffer overflow attacks and these are not controlled by the other - no options so generally you want to turn these on if you have any any if you're taking in and put from the user at all so some machine dependent options you're gonna work with these if you ever end up doing cross compilation for another computer say your writing said you know just taking any of the ECE courses 20:49 for example that's your compiling code for another processor in msp430 so you might have to work with some of these I'm using some of them in my work on first robots we use a PowerPC architecture and we're moving to an ARM architecture so we use these so - ma bi it selects the application binary interface which is the ABI or how the binary file is formatted every different version of the process every different per micro processor architecture there we go has a different version of how files are formatted so the strings section for example is in one place in x86 binaries and it's in totally different place for arm so this specifies that file format - am big or little-endian that specifies the art the endianness of the processor this is whether bikes are stored low to high or high to low in memory so mr CH specifies the target architecture so if I'm compiling for ARM version 5 II it would be - M arch equals ARM version ARM arm v5 underscore II I think I know that off the time I had this little scary and then you know you can use x86 64 for traditional computers you don't have to specify this if you're compiling for the length for the computer which you're compiling on so just a tradition traditionally this this defaults to whatever you're compiling on so if I compile on this computer it's going to work with x86 and x64 if I compile if I manage to make a compiler that ran on the msp430 then it would compile for the msp430 you're not going to make one that works on the msp430 but good luck so some other options that we've seen I'm not going to go through all the different options because we'd be here forever so we've already seen these options - V - patch - C - D and - oh you know these are the preprocessor compiler assembler of these you're probably going to work with - D - C and - oh the most debugging options - G turns on symbols so basically when GC if you noticed when we were looking at the object file GCC doesn't leave anything of your code in there so when you're debugging there's no way of knowing where you actually are in your code compared to where you are on the binary so - G will turn on leaving information in the binary so that you can actually link them so that when you use gdb instead of instead of getting a trace of oh you're in some function and this is this is the assembly code line you're in Strip you're doing you can actually tell what line of code you're on what is null what the variable names are and this gives you if you work with gdb or you work with eclipse or any of the other debuggers this is what gives you that ability to see things - version - - version prints out the version number and exits it's pretty straightforward - - help prints out help and generally tells you to go read the man pages so I'm gonna turn it over to rob well any questions about GCC compiling and curiosities all right how does most ones simply microphone not simply all right so what is make make is a UNIX the note Linux terminal command it's it's on they basically all the terminals that you'll ever use this microphone is not simple okay so what happens when you call make is it calls the terminal command make and then it the terminal will search for a file in the current directory and that file will be one of these three names would be GNU make file make file or make file it actually makes a difference if you spell them differently so make will search for that file and then execute commands from that file and I'll explain how that works in the next slide but more on a higher level make is utility for building programs the most common use of a make file is putting your GCC build commands in you know with all the all the different compiler flags and all those flags that most people never remember but Fred remembers I don't remember them so I write make files so there's other advantages to make files you can label program dependencies so basically so that you make your dog files before you make your executable files if you do those things as as individual steps there's also makes also really powerful because if it's made a dot o file before there will be a timestamp on that dot o file and if that file is up to date with the original C file it was compiled from make will actually be smart enough to not go through the compile again and it will just skip over it and say hey it's done and do a lot of really intelligent things for you and it's also like in a really abstract way it's a way of writing scripts for terminal commands so now moving on how you use a make file so so these are each of these is just a command you can call in your Linux terminal so if you went to putty you could call make from any directory and you know the terminal will try to find your make file if they make files there it'll open it make all will run all of the programs that are in the all list which I'll go over how you set that but if you don't actually define what all is and your make file these two first commands are the same so for general use you'll name your commands like program one and clean so program one would make program one you know call all the GCC commands to make it and then clean would it's what I use to clean directory basically clean out object files or clean out temporary files so how to make a make file it's really simple um this this actually makes it look more complicated than it is it's really just targets which are like these command names like program and clean so targets components and commands so components are either files that make will check for changes like it'll check your dot C files if you specify them it'll check them before it tries to compile things and if those dot C files haven't been changed to make won't do anything can also use this to call other make commands which I'll go over shortly and then the rest of it is just a series of commands which are literally just Linux terminal commands you can put GCC to compile you can change directory you can even you can just you can send emails like automated emails like that just anything you can do with the terminal you can put in these list of commands underneath your target so any questions so far all right well it was a question all right yes yes you would yeah you've literally just put your commands whatever you want in the scripts or bash and then um you know name it appropriately and just call it and it'll just do it so this is like a really easy way of writing scripts or bash master so now I'm going to talk about dependencies a little and this is actually a legitimate make file it's just formatted weird so at the top we have the all which means if you don't specify a target this is what gets called so if you don't specify target program one will get called and so what program but the target program one is is it checks to see these two object files and if they haven't been made it'll actually go to these targets since the target name target name matches what's being checked and then it will try and run this before it even starts this compliation here so what actually happens when you call make program one is it checks these and says Oh need to make dot o files so it goes down here when it calls the GCC commands that we went over earlier and it just does the first compile step Oh wha all that finishes if it's all successful it goes back up here finishes that and that's how that's how dependencies work now since this last command down here hello is not in the all it won't get called so you'd have to call make hello for it to happen and then it'll echo hello on your terminal now just a note use a little pound symbol to make comments and your make files so always comment your code even comment your make files even though it's not really code that way if you go back to this later you can be like oh what does this GCC command it links things okay so that kind of stuff so there are some special commands that you can put before any line of a command in a make file like that's our question will quick check for which one so there oh yeah the output that should be a dunno that's not taught see that's not the type oh yeah alright we'll fix that before we send this out to you guys alright so some special commands you can do you can put a dash before any command or an ad or a plus and the first one ignores errors while executing so you know if you want to suppress error messages at makes it not print a standard output and that can have a special effect with like at Echo hello if you put the ad in front it'll only print the whole Oh once but if you take out the at it'll it'll show the terminal actually typing out echo hello and then the output in the next line so the app will suppress the the first printing of it and then plus will make things execute even if make is and do not execute mode which is just really special stuff also really good and make files you can write macros inside of them it's basically just like pound defines from earlier it works kind of similar you just write whatever your name is and then equals whatever I have this first one here just uses a variable so macro one equals twelve so whenever I want to use macro one I just expect a twelve to be put in and it'll be textually substituted in so here's another example is compile GCC star dot C which is gonna look for all C files in the current directory and compile them into executables so that's what that macro expands to and then down here I made a target called GCC it's probably not a good name for it but right here is how you actually use the macro it uses a notation money sign open paren and then you have your macro name and then you close the prin and then when you actually call it it'll substitute in the values for the macro so questions before I move on I start getting fancy so one special thing about every line in your make command is it's actually technically run in a different terminal instance so it's basically like opening up another putty session for every line and that can have some different different effects so in this first example I have changed directory to a directory so it'll change the current directory of that instance of that terminal but then on the next line within a new instance so it's like we never actually changed the directory and if you're writing longer make files this can get to be a bit of a problem like say if you have read a make file to compile these programs navigate to this directory find a file move the file and that kind of stuff then you want to have the same instance for you know each command and make file so what you can do down here is you put a little semicolon and slash and that indicates to the to the make command to say hey maintain the instance I want to I want LS in the directory that I just changed to so that can make for you know really useful and longer make commands so now like the end result of writing your make files is you can do things like automated testing which I don't know what classes you guys have done so far but in the higher level classes testing your programs is basically equivalent to getting an egg like you have to test your programs if you're gonna pass and so this is a really easy way to make it easy for yourself to test so this first line I have a really really basic compile command so it compiles it and then I have test one two and three so test each of them depend on program one you know being done so basically it makes sure that program one is compiled first before it can actually run the test so actually running the test in this example program takes three inputs so from standardin so you can actually do that inside of a make file as well so you you know dot slash program one and then the three inputs just like if you're in the terminal you can do it in the make file so with this you can make it really easy for yourself to test so you're gonna be like make test three and it runs the test for you you don't have to you don't have to do the bill you don't have to do the manual inputs for running the program twice it'll just do it all for you and you'll see the output and when you have longer tests like say you run the program ten times in a row this will save you a lot of time a lot of typing so just some random stuff these are well the first one is a useful thing that I like to put in my make files and some professors ask you to do that when you submit code with the make file first one was RM dash RF blah blah star dot txt and then a little squiggle so little squiggle indicates that it's a temporary file and dash RF will recursively remove everything that matches this whether it exists or not so it kind of suppresses warnings and then just does things for you so I remove all temporary text files and all temporary dot C files also the standard cleaned that professors want is remove the dot object files you'd also you can add the names of your compiled programs your executables so we'll do it as a little clean out everything so that next time you run make all for example it'll reap recompile your whole program fresh and just restart it just in case you thought something weird was happening with the compile process so you can call make clean to delete things right and then that's that's a random one just random commands like date SLE mate and this is an example of actually changing directories and and maintaining the instance so it'll make a new directory in the current directory change into it and then change back to the original so just random stuff and so do we have any questions all right question mm-hm comments and if you're asking about like how to style the makefile lawyer like how to organize it I don't have a good answer for that but I can recommend comments and intuitive naming yeah so I mean the general the four smaller programs at least that you might be working on in any NEC course at WPI for example one of the things that the common practice is how you have a target for every single one of your dot C files which produces a dot o file and then you have a common target that takes all those Auto piles and turns them into or all target it takes all the old files and turns them into a program and that can be decently usable if you comment it well for most small programs you want to see how really really really large programs manage it pull on the source of the Linux kernel and take a look at their mega files they're insane they're make files are huge so does that answer your question or it's also a lot of really good resources online for stuff like this make make is a really well documented and very powerful tool that can do a lot of things for you and I'm just going to try and find my short demo oh yeah yeah yep yeah I believe there's also they're also ways of reading your current directory I don't know my Linux commands very well but I'm sure there's a way of reading the current directory and seeing what files are there yeah so so another thing you can do say for example we have debug so remember think back to the debugs from my presentation where I had to wear it to specify - D debug in GCC what we can do is we can have a make with a target of debug and what that will do is it will actually we have we have a variable for the compiler CC we call it okay so we set it equal to GCC and then we use it everywhere we're compiling we use DC we use CC but in my debug target you can actually have multiple targets with the same name on multiple lines and that will call them one after the other so we can have the first line where what it does is it just plus equals the CC with - D debug and then it calls all so everywhere else everywhere else it's now replaced GCC with GCC - G - G debug - D debug so now it's turned on all of that debug stuff easily and we don't have to go and change anything in the code we don't have to change anything anywhere else it's just simple make debug all right and I just got some more demo stuff so this is a make file already wrote it has a command in it make help and all it does is it basically prints the file so you can see it you see my first command is all and it does some hello stuff and something I didn't mention before there are actually more variables than are in your make file there are environment variables that are local to your system so for example log name will be my log name because I'm logged into this session and you can read those in the make file basically the same is how you can read them from a terminal command so I also have an example of variable where I just put it in quotes and then later it'll get printed I believe or not you made any oh yeah here it is so it prints it there there's just all kinds of useful things you guys want to see anything specific or any more questions yeah what do you mean when you say compiled a header file you don't compile no never they just have definitions in them they went all they have is definitions in them so they're literally just expansions when remember earlier there's a whole bunch of stuff on top of that pre-processed file it literally took the contents of printf dot h and put them there this literally what it did it is just a way of putting things so you don't have to type everything that's innate in the dot H file in all of your different files what you could do if you wanted to I wouldn't recommend it at all but you could is you could copy that header file put them in all of your different other source files usually GCC might get angry because of multiple definitions of things but if you did the proper defined guards who could and then it would be the same thing to the preprocessor the exactly the same thing all it does is it takes the header files and it puts them in your daughter cause it's all together yeah yeah the end result is that yep yeah aha very good question I will show you in a second we're gonna switch it over oh yeah because that one's not recording okay this is mine come on there we go okay now that the now that the assignment is due I can actually show this without giving away secrets okay so this was this was my implementation of your program three but this is this is the define guard okay so here we have if def process edge so if process that H has not already been defined somewhere else then define process H include all of this junk all of this stuff and then NDF right so anywhere else that includes process that H will come to this if in death if not defined process that H and we'll say false process that H is already defined and that's it we're done so that's how that's how you define things in multiple places or include header files in multiple places define guards use them use them all the time don't write a header file without them even if you're only including in one place yes it and you can test this yourself you just make a header file with with the defined guard and some stupid macro in the middle or a function definition and if you try to include it into a C file twice and it has the defined guards it'll compile properly but I believe you get an error it'll get an error for having multiple definitions if you don't have that defined guard yep and it's just a really trivial thing shot any more questions curiosities yeah we're gonna compile anything yeah yes it it won't ever in Lennox Newton well for the file extension on it it will obey the national flag but like on a UNIX if you don't put the - oh so rename it it'll output a file called a dot out blueprint yeah yeah they've gone out is what's usually done if you don't hook the deco line otherwise it'll just it throws pops you in the way of the students you know what you're doing when you put that - oh do it and that's the thing about Linux and UNIX you can you can just call executable files at your new dot slash wow man and if it's compiled to be an executable it'll run but it will have nothing to do with the file extension so okay so again question I'm sorry I didn't hear you won't do it automatically but next time you call make and targets that depend on that h-file if they're if targets that depend on a spyler call then it'll be like oh okay so the h-file change I have to do this yes you can include dependencies yeah yeah so I have made a quick example of the debug I was talking about earlier so if we look at this make file we say we have a target named all and I have a variable called CC which is which is three places with GCC and it just compiles Hallowell dot C to hello world so if I go to my shell and I run make okay here we see that it just does exactly what we expected it to GCC - C - oh hello world but if we look at the bug we can see here my first statement is debug CC plus equals - G - D debug and that says make this modification to this variable it doesn't depend on any targets and it doesn't have any commands run after it and that's it next it then calls the all target so it says run this target so if we make this with debug if we call the debug target we can see that it added - G - D debug into that command yes well okay so so you can you can do that with any any operating system we'll know that like docx is supposed to open things but if I go to a terminal and I do dots like like so for example if I do GCC - oh hello world dot this is a very long extension Linux doesn't care hello world dot C okay I now have hello world but this is a very long extension yeah Mac and Windows will try and do things for you that's like the nature of the operating system yeah that's how I like on a Windows computer you'll see like choose this default program all the time like or any time you log on to a school computer and you change from Internet Explorer it's like choose Mozilla is the default that's because it's actually trying to decide what program it should run when it sees a dot HTML HTML dice shown v whatever that's because it's trying to decide what program it should use when it sees this extension that being said you can open anything in any other program provided that you use the open with dialog so say on Windows for example I need something program dot Docs and then I went into any bits of an actual program right I can still go into a terminal and a command prompt and run it as just dot slash program Docs and it will run provided that it's a runnable thing yeah that'll have to do with the internal formatting of a file they things beyond the extension it will faithfully try to run a doc document file it will not work but it will try other questions Chris you'll click view of a question all right huh I took exactly in one hour all right it's a quick question how many of you are from CS 2303 right yep 23 so just about all you all right just curious all right well thanks everyone for coming we
Info
Channel: Upsilon Pi Epsilon at WPI
Views: 12,715
Rating: 4.9236641 out of 5
Keywords: WPI, UPEvents, software, GNU Compiler Collection (Software), Make (Software)
Id: OnEF1MexJlI
Channel Id: undefined
Length: 58min 36sec (3516 seconds)
Published: Fri Feb 14 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.