




C/C++
Thead Owner : Kurt Manion,
Category : Everything Coding,
14 Comment,
436 Read
Viewers:
1 Guest(s)
09-04-2011, 09:01 PM
so sorry for me absence hurricane Irene knocked out my power, and I just got it back, and in my opinion it shows how ineffective one singular electrical company can be >:(
Hopefully I'll have tut1 done today, and maybe even tut2!
P.S. I fixed the above post. sorry for the inconvenience ;)
Hopefully I'll have tut1 done today, and maybe even tut2!
P.S. I fixed the above post. sorry for the inconvenience ;)
09-05-2011, 03:38 PM
I tried posting here, but it keeps truncating it off after an apostrophe ::)
I've contacted Timper about it, but you can veiw it here as well.
http://www.gamemakersgarage.com/cgi-bin/...tart=15#15
sorry for the inconvenience :-\
I've contacted Timper about it, but you can veiw it here as well.
http://www.gamemakersgarage.com/cgi-bin/...tart=15#15
sorry for the inconvenience :-\
09-08-2011, 09:00 PM
part2: tut1: compiling with gcc
http://gcc.gnu.org/install/index.html
http://en.wikipedia.org/wiki/COMMAND.COM
This is in no way a tutorial of how to use Xcode. You'll pick that up through my videos, and trial-and-error. This is how to compile from the command line. So that you know what happens behind the scenes on Xcode.
for Mac you already have the gcc compiler if you downloaded Xcode, but can get it separate by downloading it form above. On Windows you must download it from above, unless you have it from the Windows version of Xcode.
Okay now that you have the actual software lets begin. Open a simple text document (textedit or notepad) and change it to simple text (only necessary with textedit.) Now type this into it
you should recognize this as our hello world application from before.
Anyways save this as main.c into your user folder. Notice the extension is '.c'. Now open up the command prompt (Terminal for mac and cmd for windows). For Mac it's an application in the utilities folder, in your applications folder. For Windows type cmd into run, you can also find it at your systems32 folder, and you can make one (good for gaining access to computer internals when your unauthorized) by opening note pad and typing COMMAND.COM into the file and saving it as an .exe . you should change your default window to something cooler than black and white, with ms-dos you can use the command color and with terminal you can set it in Terminal > Preferences .
Before going on I should mention that I will passingly mention a few UNIX commands, and they of course will not work on your pc machine, but you can find similar if not identical commands at the wikipedia link.
Another thing before going on a mac you can type in and assuming you understand their archaic documentation you can scrap the rest of this tutorial!
Now lets get down to business. Assuming you saved it too your user folder terminal starts up there by default, but if you did not change the directory to that folder using the cd command. (note that the words directory and folder are synonymous.) and type this compiles and links your application and gives it the default name a.out . Your machine still retains the source file (main.c). Most tutorials say just to type a.out to run it, but that involves putting it in your bin or some root access like that, that is unnecessary. The command that will always work is: that basically means open a.out through the command prompt (terminal.) Since I do not have a pc I ca not even begin to help you with this, but I confer with Ryan (Lombardi), and we will make an edit here for the pc users, and notify you. so you will see hello world written probably written in your boring black and white if you did not listen to me. just close it and go back to your main window. There are tons more options for you to use. Before going on I would like to remind you that you can use multiple files to create your application. These files are called modules. lets say your finished with one and do not need to use it anymore, or want to let a friend use it without seeing whats inside of it. you can compile it without linking, by making an object file. this creates main.o an object file that you can latter link to your program just like it was a source file. The upside to this is, if your machine is slow, or your program is huge then you do not have to have the machine compile the whole application every time, just the source files, it only has to link the object files. (which is a relatively quick process.)
You can also define variables to be passed to the application at the preprocessing stage. This will not seem very important to you unless your already familiar with the #ifdef statement, but I will elaborate on its importance during the discussion of the preprocessor.
It is called the -D switch. The syntax is simple or fig1 makes an uninitialized variable DEBUG, and fig2 makes a variable MACHINE initialized to 1. Again you can not see the infinite importance of this, but trust me its very important.
Optimization command -O (capital o) switch. just place it before every thing on the very last compile. Simply optimizes it.
The last, and probably most used command is the -o switch (lower case o). It allows you to name the program. This makes a compiled, and linked C program called program.
On two parting note gcc syntax is identical for compiling C, C++, Objective-C, Objective-C++, and I believe java, but I do not know anything java so do not take my word on that one.
The command you may see some C programmers learn cc is identical to gcc, but I think it only works with C programs.
P.S. This video for this one will be a little late, because I have to try a screen emulation with Ryan (Lombardi) so the windows people do not feel left out. Wow I never thought id be accommodating for pc!
http://gcc.gnu.org/install/index.html
http://en.wikipedia.org/wiki/COMMAND.COM
This is in no way a tutorial of how to use Xcode. You'll pick that up through my videos, and trial-and-error. This is how to compile from the command line. So that you know what happens behind the scenes on Xcode.
for Mac you already have the gcc compiler if you downloaded Xcode, but can get it separate by downloading it form above. On Windows you must download it from above, unless you have it from the Windows version of Xcode.
Okay now that you have the actual software lets begin. Open a simple text document (textedit or notepad) and change it to simple text (only necessary with textedit.) Now type this into it
Code:
main()
{
  printf("hello world.\n");
}
Anyways save this as main.c into your user folder. Notice the extension is '.c'. Now open up the command prompt (Terminal for mac and cmd for windows). For Mac it's an application in the utilities folder, in your applications folder. For Windows type cmd into run, you can also find it at your systems32 folder, and you can make one (good for gaining access to computer internals when your unauthorized) by opening note pad and typing COMMAND.COM into the file and saving it as an .exe . you should change your default window to something cooler than black and white, with ms-dos you can use the command color and with terminal you can set it in Terminal > Preferences .
Before going on I should mention that I will passingly mention a few UNIX commands, and they of course will not work on your pc machine, but you can find similar if not identical commands at the wikipedia link.
Another thing before going on a mac you can type in
Code:
man gcc
Now lets get down to business. Assuming you saved it too your user folder terminal starts up there by default, but if you did not change the directory to that folder using the cd command. (note that the words directory and folder are synonymous.) and type
Code:
gcc main.c
Code:
open -a terminal a.out
Code:
gcc -c main.c
You can also define variables to be passed to the application at the preprocessing stage. This will not seem very important to you unless your already familiar with the #ifdef statement, but I will elaborate on its importance during the discussion of the preprocessor.
It is called the -D switch. The syntax is simple
Code:
gcc -D DEBUG main.c
Code:
gcc -D MACHINE = 1 main.c
Optimization command -O (capital o) switch. just place it before every thing on the very last compile. Simply optimizes it.
The last, and probably most used command is the -o switch (lower case o). It allows you to name the program.
Code:
gcc main.c -o program
On two parting note gcc syntax is identical for compiling C, C++, Objective-C, Objective-C++, and I believe java, but I do not know anything java so do not take my word on that one.
The command you may see some C programmers learn cc is identical to gcc, but I think it only works with C programs.
P.S. This video for this one will be a little late, because I have to try a screen emulation with Ryan (Lombardi) so the windows people do not feel left out. Wow I never thought id be accommodating for pc!
09-19-2011, 09:57 PM
sorry I haven't posted in forever. I've been researching on how to integrate your own command prompt applications into your mac. I've finally found out how, but it's a bit complicated. I'm writing it up now, and will hopefully be done tomorrow.
09-22-2011, 10:49 PM
so it still cuts things off after the apostrophe
just view it as a pages doc, first link, or ms word second link
http://www.mediafire.com/?35fgfgm0b74rr21
http://www.mediafire.com/?1re3td858r209k5
just view it as a pages doc, first link, or ms word second link
http://www.mediafire.com/?35fgfgm0b74rr21
http://www.mediafire.com/?1re3td858r209k5