Jun 30 22:32:55 <-- CLASS STARTED --> Jun 30 22:33:02 roll call Jun 30 22:33:09 deepak kumar Jun 30 22:33:12 Ratnadeep Debnath Jun 30 22:33:12 Pushkal Srivastava Jun 30 22:33:15 Atanu Bera Jun 30 22:33:17 amrita mukherjee Jun 30 22:33:19 Neeraj Kumar Jun 30 22:33:22 chikan banerjee Jun 30 22:33:22 ria das Jun 30 22:33:27 Prakhar Agarwal Jun 30 22:34:09 kishan goyal Jun 30 22:34:46 * chacha_chaudhry (n=dev@gnu-india/supporter/rakeshpandit) has joined #dgplug Jun 30 22:35:07 <_pjp_> okay friends, let's start. Jun 30 22:35:29 ok Jun 30 22:35:50 <_pjp_> So far we talked about gcc and it's compilation steps and some useful options. Jun 30 22:36:19 <_pjp_> Today continuing the same, we'll see some more useful options of gcc Jun 30 22:36:25 arpita kapoor Jun 30 22:37:06 <_pjp_> After -o, -c, and -x, next useful and important options is -std Jun 30 22:37:48 ! Jun 30 22:38:03 <_pjp_> -std let's you specify the C language standard you want to follow. Jun 30 22:38:12 <_pjp_> atanubera, ? Jun 30 22:38:15 what is -std? Jun 30 22:38:45 atanubera, please check yesterday's log file Jun 30 22:38:52 ok Jun 30 22:39:13 <_pjp_> As I said yesterday, there are more than one C standards today. Jun 30 22:39:14 atanubera, and then let him speak Jun 30 22:39:47 <_pjp_> The most widely used and supported by all the c compilers is standard C89. Jun 30 22:40:23 * nandy_lost (n=chatzill@59.178.181.30) has joined #dgplug Jun 30 22:40:58 <_pjp_> also know as -ansi Jun 30 22:41:19 * kushal gives channel operator status to _pjp_ Jun 30 22:41:59 <_pjp_> The latest C language standard is C99 but is still not supported by all the C compilers. Jun 30 22:42:23 <_pjp_> And that makes you take the call of code portability. Jun 30 22:42:51 ! Jun 30 22:43:10 * mavu (n=satya@59.178.170.242) has joined #dgplug Jun 30 22:43:19 chiks, please ask later Jun 30 22:43:38 * mavu is now known as mavu_ Jun 30 22:43:51 <_pjp_> i.e: If your C code follows C99 and you want to compile it with X compiler for Y platform, it is *necessary* that X understands C99 standard Jun 30 22:44:29 <_pjp_> I personally use -ansi Jun 30 22:44:43 * roni (n=aritra@117.201.96.75) has joined #dgplug Jun 30 22:45:45 * Debashree_ (n=Debashre@61.0.133.58) has joined #dgplug Jun 30 22:46:00 <_pjp_> It has a future advantage that, when the implementation of C99 is over and widely supported, -ansi might become -std=c99 Jun 30 22:46:34 * Debashree has quit (Nick collision from services.) Jun 30 22:46:54 <_pjp_> anyways, so to use -std or -ansi just say: $ gcc -x c -std=c89 -o hello hello.c -lm Jun 30 22:46:57 * Debashree_ is now known as Debashree Jun 30 22:47:13 <_pjp_> or $ cc -x c -std=c89 -o hello hello.c -lm Jun 30 22:47:42 <_pjp_> Also try to compile the same code with -std=c99 Jun 30 22:48:53 <_pjp_> You may not see any errors/warnings but as the code grows, and you use the latest language features, you'll start to notice the differences Jun 30 22:49:20 <_pjp_> -ansi could be used as $ gcc -x c -ansi -o hello hello.c Jun 30 22:50:37 * t4num0y_cs3 has quit (Read error: 104 (Connection reset by peer)) Jun 30 22:51:44 ! Jun 30 22:51:46 ! Jun 30 22:51:51 ! Jun 30 22:51:55 <_pjp_> arpita, deepak susenj ? Jun 30 22:52:14 _pjp_, the last command is showing errors Jun 30 22:52:23 <_pjp_> what errors? Jun 30 22:52:26 do i need to use option -x c altogether Jun 30 22:52:44 all these three commands are giving warnings Jun 30 22:52:52 <_pjp_> Well..-x c is not always required. Jun 30 22:53:15 <_pjp_> what warnings? Jun 30 22:53:29 * chacha_chaudhry has quit (Connection timed out) Jun 30 22:53:33 incompatible implicit declaration of built-in function ‘sqrt’ Jun 30 22:53:54 gcc -x c -ansi -o hello hello.c -lm _pjp_ this worked fine for me Jun 30 22:53:58 arpita ,use -lm with the last command Jun 30 22:54:02 _pjp_, undefined reference to square root Jun 30 22:54:18 [deepak@localhost ~]$ gcc -x c -ansi -o hello1 hello1.c Jun 30 22:54:18 /tmp/cclfFBQ9.o: In function `main': Jun 30 22:54:18 hello1.c:(.text+0x45): undefined reference to `sqrt' Jun 30 22:54:18 collect2: ld returned 1 exit status Jun 30 22:54:25 <_pjp_> ah..sorry..I missed the -lm in the last one. Jun 30 22:54:29 deepak, USE rafb.net/paste Jun 30 22:54:31 use -lm please Jun 30 22:54:59 _pjp_, yes now working........ Jun 30 22:55:08 kushal:ok ,but it was not long Jun 30 22:55:22 what about the warnings,i found? Jun 30 22:55:35 Jun 30 22:55:41 <_pjp_> Please try to read and follow the error messages, they are quite indicative Jun 30 22:55:55 <_pjp_> susenj, what warnings? Jun 30 22:55:59 deepak, USE http://rafb.net/paste Jun 30 22:56:07 warning:incompatible implicit declaration of built-in function ‘sqrt’ Jun 30 22:56:11 Jun 30 22:56:24 yes , it is working after using -lm Jun 30 22:56:33 kushal:ok Jun 30 22:56:35 <_pjp_> susenj, have you included the math.h file? Jun 30 22:57:04 when i have linked with math library,is it necessary to include it as well? Jun 30 22:58:05 <_pjp_> he..he..yes dear, they serve two different purposes, I'll come to that shortly. Jun 30 22:58:32 okay Jun 30 22:58:39 <_pjp_> so is it working for all? Jun 30 22:58:46 ! Jun 30 22:58:49 yup,no errors Jun 30 22:59:47 ! Jun 30 22:59:52 yes Jun 30 22:59:58 <_pjp_> Okay, the next option is -I , that's capital i Jun 30 23:00:51 <_pjp_> So far we've used two header files in hello.c, stdio.h and math.h, right? Jun 30 23:01:25 yes Jun 30 23:01:44 <_pjp_> The header files are suppose to contain certain declaration and #include statements. Jun 30 23:02:35 <_pjp_> They can contain macro definitions, function declarations, or declarations of user defined data types in C Jun 30 23:03:18 <_pjp_> User defined data types like structures, unions, function pointers etc. Jun 30 23:03:32 * coolpyro_rishi (n=chatzill@202.63.119.36) has joined #dgplug Jun 30 23:04:22 <_pjp_> Did you wonder how gcc knows about printf () and sqrt () functions? Jun 30 23:04:56 <_pjp_> C is known to be a strongly typed language. Jun 30 23:06:14 * Prams (n=prams@125.20.11.34) has joined #dgplug Jun 30 23:06:25 <_pjp_> Everything has to be explicitly and precisely declared before you can use it. Otherwise gcc could make some assumptions and generate wrong/non-portable or sometimes even buggy code. Jun 30 23:06:26 Jun 30 23:06:56 * chiks has quit ("ChatZilla 0.9.83 [Firefox 2.0.0.14/2008040413]") Jun 30 23:07:29 <_pjp_> The declarations for functions printf() and sqrt() could be found in stdio.h and math.h respectively. Jun 30 23:08:29 <_pjp_> If you don't declare a function before use, gcc assumes that it'll returns an integer value, and apply the relevant rules while compilation. Jun 30 23:09:05 <_pjp_> Which can result in compilation errors/warnings etc. Jun 30 23:09:37 <_pjp_> Now, the questions comes is where are these files stdio.h and math.h? Jun 30 23:09:54 <_pjp_> and how does gcc finds them or knows about them? Jun 30 23:10:30 is there not a library? Jun 30 23:11:45 <_pjp_> right..the stdio.h and math.h are standard library files, which are shipped with libc, i.e. standard C library Jun 30 23:12:06 <_pjp_> they are located under /usr/include and gcc know about it. Jun 30 23:12:44 * arpita_ (n=arpita@117.201.97.208) has joined #dgplug Jun 30 23:13:04 * ICEMAN_ (n=chatzill@125.20.11.34) has joined #dgplug Jun 30 23:13:04 * ria_ (n=ria@121.245.35.212) has joined #dgplug Jun 30 23:13:22 * ria has quit (Nick collision from services.) Jun 30 23:13:24 in case of gcc i can't run the graphics lin draw codes. Jun 30 23:13:29 * ria_ is now known as ria Jun 30 23:13:38 * ICEMAN_ is now known as Atanu_bera Jun 30 23:13:48 Prams, ask for permission then only speak Jun 30 23:13:56 ! Jun 30 23:14:17 <_pjp_> please see: $ gcc --print-search-dirs Jun 30 23:15:03 * t4num0y_cs3 (n=Neo@117.194.2.207) has joined #dgplug Jun 30 23:15:14 sorry kushal Jun 30 23:15:46 ! Jun 30 23:16:12 <_pjp_> it displays the directories that gcc looks into for headers and libraries. Jun 30 23:17:42 <_pjp_> the lib and include directories are known to be under the same parent directory, so you may not find the include directory path in the above output. Jun 30 23:18:12 ! Jun 30 23:18:39 * t4num0y_cs3 has quit (Client Quit) Jun 30 23:18:41 <_pjp_> If you include a file using angular brackets , gcc looks for these files under the predefined search path. Jun 30 23:19:57 <_pjp_> Try including hello.h in you program as #include Jun 30 23:20:20 <_pjp_> compile it, and see what happens Jun 30 23:20:38 * Debashree has quit (Read error: 104 (Connection reset by peer)) Jun 30 23:21:12 ! Jun 30 23:21:19 hello.c:3:18: error: hello.h: No such file or directory Jun 30 23:21:37 same^^^ Jun 30 23:21:43 >_pjp_< take the questions Jun 30 23:21:51 >_pjp_< nandy_lost is first Jun 30 23:21:51 ! Jun 30 23:22:00 mine too Jun 30 23:22:02 <_pjp_> Great..now say: touch hello.h Jun 30 23:22:03 * arpita has quit (Read error: 110 (Connection timed out)) Jun 30 23:22:07 hello.h is not not any defined header file Jun 30 23:22:20 * Debashree (n=Debashre@61.2.164.230) has joined #dgplug Jun 30 23:22:22 <_pjp_> deepak, say: touch hello.h Jun 30 23:22:40 all please follow what _pjp_ says Jun 30 23:23:00 even then Jun 30 23:23:02 same error Jun 30 23:23:13 <_pjp_> and then compile the hello.c as: $ gcc -x c -ansi -I ./ -o hello hello.c Jun 30 23:23:18 _pjp_, we will write #include Jun 30 23:23:32 _pjp_, inside program or in command prompt? Jun 30 23:23:57 <_pjp_> ./ is for current working directory, that is where you created the hello.h file. Jun 30 23:23:57 arpita_, where do you wrote #include lines before ? Jun 30 23:24:25 -lm too people ! Jun 30 23:24:29 again -lm is left ,i think! Jun 30 23:24:39 it's working now Jun 30 23:24:47 * atanubera has quit (Read error: 110 (Connection timed out)) Jun 30 23:24:52 <_pjp_> ah.gawd..yes -lm is required. Jun 30 23:24:58 ya adding -lm give no errors Jun 30 23:26:45 _pjp_:means we created a empty header file Jun 30 23:27:04 without -I ./ it gives error as no directory.. with it it runs Jun 30 23:27:06 <_pjp_> So, did you get when and why to use -I ? Jun 30 23:27:14 yes Jun 30 23:27:15 absolutely Jun 30 23:27:27 yes Jun 30 23:28:00 <_pjp_> with -I you are instructing gcc to also search the specified directory Jun 30 23:28:15 * nandy_lost_ (n=chatzill@59.178.169.243) has joined #dgplug Jun 30 23:28:27 ! Jun 30 23:28:33 * t4num0y_cs3 (n=Neo@117.194.2.207) has joined #dgplug Jun 30 23:28:37 * techno_freak has quit ("Leaving") Jun 30 23:28:39 <_pjp_> arpita_, ? Jun 30 23:28:54 <_pjp_> now, change #include to #include "hello.h" Jun 30 23:29:24 _pjp_, on including hello.h and then compiling using gcc -o hello -lm hello.c Jun 30 23:29:24 it is showing no such file name found Jun 30 23:29:27 <_pjp_> and compile without -I ./ option Jun 30 23:29:46 works Jun 30 23:29:58 * mether (n=ask@fedora/mether) has joined #dgplug Jun 30 23:29:58 <_pjp_> arpita_, -I ./ Jun 30 23:30:05 _pjp_, o.k Jun 30 23:30:27 * suse_nj (n=root@59.178.169.243) has joined #dgplug Jun 30 23:30:29 it worked Jun 30 23:30:47 * indradg__ (n=indradg@59.93.216.129) has joined #dgplug Jun 30 23:31:10 ! Jun 30 23:31:13 ! Jun 30 23:31:18 <_pjp_> so, if you include a header file using double quotation("), gcc understands that file is in the same directory and the source file. Jun 30 23:31:36 <_pjp_> suse_nj, arpita_ ? Jun 30 23:31:37 _pjp_, still same error is showing..no such filename even with -I option Jun 30 23:31:39 so, -I ,includes whatsoever file we want to include in our program,should they be always .h files? Jun 30 23:32:03 <_pjp_> arpita_, -I ./ Jun 30 23:32:44 arpita_, did you created that file with touch command ? Jun 30 23:32:46 <_pjp_> suse_nj, -I only specifies the search directory path. Jun 30 23:34:18 <_pjp_> suse_nj, yes do not include any other file other than .h even though it is possible to include source files(i.e. .c or .cpp files). Jun 30 23:35:00 ok Jun 30 23:35:02 <_pjp_> so far..all with me? Jun 30 23:35:03 _pjp_, yes now no errors Jun 30 23:35:05 one more query Jun 30 23:35:09 now to execute?? Jun 30 23:35:16 <_pjp_> arpita_, congratulations. :) Jun 30 23:35:24 <_pjp_> suse_nj, ? Jun 30 23:35:26 yes Jun 30 23:35:30 touch command is used for changing the timestamps for a file,it was taught last night.the same purpose here?? Jun 30 23:35:52 suse_nj, and also to create an empty file if the file does not exist Jun 30 23:36:17 <_pjp_> suse_nj: No, touch creates a file if it is not there. Jun 30 23:36:43 ok,probably i didn't read the manual well! :( Jun 30 23:38:07 * mitesh_ (n=chatzill@121.247.228.161) has joined #dgplug Jun 30 23:38:07 Jun 30 23:38:07 <_pjp_> Okay, the next option -L is same as -I, just that it works for the library(.a or .so) files instead of header(.h) files. Jun 30 23:38:30 ! Jun 30 23:38:40 <_pjp_> when you say -lm, gcc looks into the predefined search directories for the relevant library file. Jun 30 23:38:42 <_pjp_> arpita_, ? Jun 30 23:38:53 * mitesh_ has quit (Client Quit) Jun 30 23:39:16 _pjp_, when we say touch hello.h it creates an empty file of name hello.h? Jun 30 23:39:41 arpita_, correct Jun 30 23:39:42 <_pjp_> arpita_, right! Jun 30 23:40:05 * mether has quit ("Ex-Chat") Jun 30 23:40:25 _pjp_, and what is the use of including the file hello.h created in the program hello.c? Jun 30 23:41:26 * prams_ (n=chatzill@125.20.11.34) has joined #dgplug Jun 30 23:41:28 <_pjp_> arpita_, well..let's see Jun 30 23:41:59 * Soumya (n=Soumya@59.164.98.140) has joined #dgplug Jun 30 23:42:06 * Soumya_ (n=Soumya@59.164.98.140) has joined #dgplug Jun 30 23:42:35 <_pjp_> Now to make use of the -L option, will have to add some more complications to our hello.c Jun 30 23:43:14 * prams_ has quit (Client Quit) Jun 30 23:43:46 * Soumya has quit (Nick collision from services.) Jun 30 23:43:52 * Soumya_ is now known as Soumya Jun 30 23:43:58 * Prams (n=prams@125.20.11.34) has left #dgplug Jun 30 23:44:17 * Soumya_ (n=Soumya@59.164.98.140) has joined #dgplug Jun 30 23:44:20 * mobilesuit_ (n=freedom@59.93.205.5) has joined #dgplug Jun 30 23:45:57 * mobilesuit has quit (Nick collision from services.) Jun 30 23:45:57 * mobilesuit_ is now known as mobilesuit Jun 30 23:45:59 * nandy_lost has quit (Read error: 110 (Connection timed out)) Jun 30 23:46:42 * susenj has quit (Read error: 110 (Connection timed out)) Jun 30 23:46:48 * suse_nj is now known as susenj Jun 30 23:46:59 kushal, ! Jun 30 23:47:20 ria, yes Jun 30 23:47:24 * samar (n=samar-ad@220.226.88.63) has joined #dgplug Jun 30 23:47:42 kushal, i cant see anyone talking Jun 30 23:47:50 * s_node (n=prams@125.20.11.34) has joined #dgplug Jun 30 23:47:57 ria, yes, because no one talking Jun 30 23:47:58 kushal, and my IRC is sometimes behaving typically Jun 30 23:48:23 hi all , I am Samarjit Jun 30 23:48:42 samar, class is going on :) Jun 30 23:49:01 i am talking now Jun 30 23:49:01 :-) Jun 30 23:49:01 kushal, i was writing something in pm and IRC was telling me unknown command Jun 30 23:49:09 probably u put a / before Jun 30 23:49:19 ria, can we discuss these things later Jun 30 23:49:19 kushal, oops ! sorry Jun 30 23:49:24 ria, class is going on Jun 30 23:49:28 samar, no problem Jun 30 23:49:48 <_pjp_> wait a sec guys Jun 30 23:49:55 kushal, sorry Jun 30 23:50:13 * stephaniewhiting (n=chatzill@209-33-197-89.dsl.infowest.net) has joined #dgplug Jun 30 23:50:56 * Soumya_ has quit ("Leaving") Jun 30 23:51:09 <_pjp_> okay ready guys? Jun 30 23:51:13 yes Jun 30 23:51:28 yes Jun 30 23:52:19 <_pjp_> Now to see how -L works, we are about to create our own library. As it'll be a bit difficult to explain it with the standard libraries. Jun 30 23:52:34 yes Jun 30 23:53:11 <_pjp_> so, first add this line to your hello.h: extern void greet (void); Jun 30 23:53:23 ! Jun 30 23:53:44 * Debashree_ (n=Debashre@61.2.165.182) has joined #dgplug Jun 30 23:54:05 added Jun 30 23:54:16 hi everyone Jun 30 23:54:22 stephaniewhiting, hi Jun 30 23:54:23 s_node samar SDey_ Soumya stephaniewhiting susenj Jun 30 23:54:24 * Debashree has quit (Nick collision from services.) Jun 30 23:54:30 stephaniewhiting, class is going on Jun 30 23:54:42 on what kushal? Jun 30 23:54:49 * Debashree_ is now known as Debashree Jun 30 23:54:58 yes added Jun 30 23:55:18 ! Jun 30 23:55:27 <_pjp_> okay then, create a file called greet.c containing: http://rafb.net/p/VOOJYJ95.html Jun 30 23:56:26 done Jun 30 23:56:32 _pjp_, extern void greet (void); has to be added by opening hello.h in vi editor?? Jun 30 23:56:37 <_pjp_> then in your hello.c, inside main(), call the function: greet (); Jun 30 23:56:53 <_pjp_> arpita_, yes! Jun 30 23:57:33 <_pjp_> so far..all with me? Jun 30 23:57:44 yes Jun 30 23:57:47 yes Jun 30 23:57:49 yes Jun 30 23:57:58 yes Jun 30 23:58:07 yes Jun 30 23:58:55 <_pjp_> cool..so now first compile the two source files with: $ gcc -x c -ansi -o hello hello.c greet.c -lm Jun 30 23:59:12 <_pjp_> and then execute ./hello Jun 30 23:59:13 * stephaniewhiting (n=chatzill@209-33-197-89.dsl.infowest.net) has left #dgplug Jun 30 23:59:26 <_pjp_> did that work? Jun 30 23:59:31 yes Jun 30 23:59:45 yes Jul 01 00:00:07 no Jul 01 00:00:08 ! Jul 01 00:00:11 <_pjp_> susenj, ? Jul 01 00:00:14 <_pjp_> ria, ? Jul 01 00:00:21 no Jul 01 00:00:25 [root@localhost Desktop]# gcc -x c -ansi -o hello hello.c greet.c -lm Jul 01 00:00:25 hello.c:3:18: error: hello.h: No such file or directory Jul 01 00:00:31 same here Jul 01 00:00:36 <_pjp_> susenj, -I ./ Jul 01 00:00:43 will void greet() be written within hello.h Jul 01 00:00:45 ? Jul 01 00:00:51 and same for me Jul 01 00:00:55 did not work Jul 01 00:01:30 <_pjp_> ria, yes, write extern void greet (void) inside hello.h Jul 01 00:02:01 _pjp_, http://rafb.net/p/VOOJYJ95.html will this be written? Jul 01 00:02:05 <_pjp_> folks don't copy paste the commands I write here. Jul 01 00:06:23 * Topic for #dgplug set by kushal at Mon Jun 30 20:39:45 2008 Jul 01 00:06:33 _pjp_, ^^^ Jul 01 00:06:42 <_pjp_> arpita_, compile with -I ./ you have angular brackets around hello.h Jul 01 00:07:06 _pjp_, will only extern void greet (void) be written in hello.h? Jul 01 00:07:21 in the same way i wrote here? Jul 01 00:07:26 * rsa_md5 (n=droopy@117.194.0.33) has joined #dgplug Jul 01 00:07:28 <_pjp_> amrita, I'll explain everything in a while. Jul 01 00:07:32 <_pjp_> ria, yes Jul 01 00:07:46 that command does not work Jul 01 00:08:10 <_pjp_> ria, don't miss the semi-colon(;) after (void); Jul 01 00:08:17 <_pjp_> ria, what command? Jul 01 00:08:26 ok in hello.h? Jul 01 00:08:39 after (void) Jul 01 00:08:47 <_pjp_> mavu_, ? Jul 01 00:08:49 i mean ;? Jul 01 00:08:59 <_pjp_> ria, yes Jul 01 00:09:03 ok Jul 01 00:09:30 _pjp_, it works fine now Jul 01 00:09:32 we did a function call to greet.. but how did it know its in greet.c? and will that work if i rename greet.c to something else and still have the function name as greet Jul 01 00:10:04 ! Jul 01 00:10:10 <_pjp_> mavu_, yes it will still work, as long as you compile the new file with hello.c. Jul 01 00:10:13 <_pjp_> deepak, ? Jul 01 00:10:22 <_pjp_> ria, congratulations! Jul 01 00:10:30 ! Jul 01 00:10:32 oh :) Jul 01 00:10:33 <_pjp_> susenj, ? Jul 01 00:10:37 _pjp_!please make the connections, more clearer!,i didn't understand well Jul 01 00:11:04 _pjp_:it is giving no such file or directory Jul 01 00:11:10 * SDey_ has quit (Read error: 110 (Connection timed out)) Jul 01 00:11:22 <_pjp_> okay..I think everybody got the correct output. Jul 01 00:11:34 _pjp_:gcc -x c -ansi -o hello1 hello1.c greet.c -lm Jul 01 00:11:34 hello1.c:2:18: error: hello.h: No such file or directory Jul 01 00:11:36 yup got the correct o/p Jul 01 00:11:38 <_pjp_> deepak, use -I ./ Jul 01 00:12:01 yup ,but didn't understand the whole program! Jul 01 00:12:23 _pjp_:again it is giving many warnings Jul 01 00:12:38 same here Jul 01 00:13:04 <_pjp_> yes, I'm about to explain the whole thing. Just few more steps. Jul 01 00:13:29 _pjp_:my file name is hello1.c Jul 01 00:14:08 <_pjp_> deepak, what do you mean? Jul 01 00:14:13 <_pjp_> could someone help Deepak if he is physically reachable to you!?! Jul 01 00:14:35 deepak,paste your code please! Jul 01 00:14:50 * roni has quit (Read error: 110 (Connection timed out)) Jul 01 00:14:56 deepak, why your file name is hello1.c ? Jul 01 00:15:06 deepak, follow what _pjp_ is telling Jul 01 00:15:40 kushal:i already created hello.c Jul 01 00:15:40 <_pjp_> deepak, -I ./ Jul 01 00:16:04 <_pjp_> deepak, $ gcc -x c -ansi -I ./ -o hello1 hello1.c greet.c -lm Jul 01 00:16:39 shows no such file or directory Jul 01 00:16:47 <_pjp_> arpita_, ? Jul 01 00:16:53 _pjp_:i also tried it but screen gets flooded with warnings and at the end giving no such file and directory Jul 01 00:17:02 deepak,could you please paste the errors in pm! Jul 01 00:17:10 arpita_, did you write hello.h, i was having the same problem Jul 01 00:17:20 i am pasting it Jul 01 00:17:38 ria, where to write hello.h? Jul 01 00:18:00 arpita_, in terminal Jul 01 00:18:17 arpita_, open it with vi hello.h Jul 01 00:18:24 arpita_, you already created it just edit it and write void extern greet (void); Jul 01 00:18:41 arpita_, and then write the above Jul 01 00:18:44 <_pjp_> ria, it's extern void ... Jul 01 00:18:47 deepak, use rafb.net/paste Jul 01 00:18:48 deepak, use rafb.net/paste Jul 01 00:18:49 deepak, use rafb.net/paste Jul 01 00:18:56 deepak, ^^ read above Jul 01 00:19:02 _pjp_, ya sorry extern void Jul 01 00:20:27 <_pjp_> deepak, I'm waiting for the link. Jul 01 00:20:27 ok Jul 01 00:21:07 _pjp_:my program is here:http://rafb.net/p/uUUgOs12.html Jul 01 00:21:40 * roni (n=aritra@117.201.97.13) has joined #dgplug Jul 01 00:21:48 "hello.h" Jul 01 00:22:21 deepak, learn how to paste the link Jul 01 00:22:22 deepak,please paste the bugs also Jul 01 00:23:06 deepak, "hello.h",greet (); both are missing Jul 01 00:23:27 <_pjp_> deepak, right, now call the function greet () inside hello.c Jul 01 00:23:42 <_pjp_> deepak, before return 0; Jul 01 00:23:49 ok Jul 01 00:24:30 <_pjp_> deepak, and then compile both the files as: $ gcc -x c -ansi -I ./ -o hello hello1.c greet.c -lm Jul 01 00:25:16 <_pjp_> others who got it working already, compile only greet.c with -c option to get greet.o file. Jul 01 00:25:40 <_pjp_> let me know when you are done. Jul 01 00:26:09 done Jul 01 00:26:18 * Soumya has quit ("Leaving") Jul 01 00:26:20 done Jul 01 00:26:42 done Jul 01 00:26:44 <_pjp_> ria, great. Now help others if you are physically reachable to them Jul 01 00:27:06 _pjp_:thanks its done. now my concept clear Jul 01 00:27:23 <_pjp_> deepak, congratulations! Jul 01 00:27:28 _pjp_, i did only gcc -c greet.c Jul 01 00:27:33 is it ok? Jul 01 00:27:47 <_pjp_> deepak, now create greet.o file. Jul 01 00:27:48 -o if we need greet.o Jul 01 00:27:51 <_pjp_> ria, yes, that's fine. Jul 01 00:27:54 i guess Jul 01 00:27:56 ok Jul 01 00:28:11 -c , mavu_ Jul 01 00:28:21 hmm Jul 01 00:28:38 done Jul 01 00:28:46 ah okay :) got it :) -o is for the executable Jul 01 00:28:50 not for object file Jul 01 00:28:51 <_pjp_> deepak, ? Jul 01 00:29:24 mavu_, -o is for using another filename instead of a.out Jul 01 00:29:38 yeah.. another name for the executable right? Jul 01 00:29:43 i thought for object file too Jul 01 00:30:06 mavu_,righto ! _pjp_ please continue Jul 01 00:30:11 <_pjp_> mavu_, -o is for output file, not just executable file. You can very well say: $ gcc -x c -o abc.o -c greet.c Jul 01 00:30:46 <_pjp_> deepak, did you get the object file greet.o? Jul 01 00:30:53 _pjp_:yes Jul 01 00:31:01 * t4num0y_cs3 has quit (Read error: 110 (Connection timed out)) Jul 01 00:31:03 <_pjp_> great..now we Jul 01 00:31:37 ! Jul 01 00:31:49 <_pjp_> we will create a static library from greet.o using command ar(1) Jul 01 00:31:49 * t4num0y_cs3 (n=Neo@117.194.0.88) has joined #dgplug Jul 01 00:31:52 <_pjp_> mavu_, ? Jul 01 00:31:55 ah.. ! so when i say that.. a -c for greet.c and -o greet is redundant? as in without -o greet also the output goes to greet.o? Jul 01 00:32:18 <_pjp_> mavu_, right. Jul 01 00:32:29 :) thanks Jul 01 00:32:39 <_pjp_> now say: $ ar cr libgreet.a greet.o Jul 01 00:33:02 * rsa_md5 has quit ("Leaving") Jul 01 00:33:27 to execute it right now?? Jul 01 00:33:40 <_pjp_> that will create a static C libray called libgreet.a Jul 01 00:33:47 <_pjp_> does you see that file? Jul 01 00:33:53 yes Jul 01 00:33:55 <_pjp_> see: http://en.wikipedia.org/wiki/Static_library Jul 01 00:34:04 ya Jul 01 00:34:19 earlier i have heard of ar crv, what is it then _pjp_ ? Jul 01 00:34:46 Jul 01 00:34:58 ria, generally in any linux command v stands for verbose Jul 01 00:35:17 <_pjp_> ria, ar is an archiving utility, that creates an archive of one or more files. Jul 01 00:35:17 all please type ! and wait Jul 01 00:35:42 ok _pjp_ Jul 01 00:35:52 ! Jul 01 00:36:12 * roni has quit ("Leaving") Jul 01 00:36:13 <_pjp_> you can see the contents of an archive file using: $ ar -tvf libgreet.a Jul 01 00:36:50 * aritra (n=aritra@117.201.97.13) has joined #dgplug Jul 01 00:37:21 <_pjp_> now, try to compile hello.c as $ gcc -x c -ansi -I ./ -o hello hello.c -lm -lgreet Jul 01 00:37:48 <_pjp_> ria, ? Jul 01 00:37:59 what is cr for? Jul 01 00:38:39 <_pjp_> c for create and r for replace, see: $ man ar or $ ar --help Jul 01 00:38:43 >_pjp_< _pjp_ :) Jul 01 00:38:49 ok Jul 01 00:38:52 Jul 01 00:39:18 it does not work Jul 01 00:39:27 mine too Jul 01 00:39:31 <_pjp_> what does not work? Jul 01 00:39:37 for me as well Jul 01 00:39:54 usr/bin/ld : cannot find -lgreet Jul 01 00:39:58 gcc -x c -ansi -I ./ -o hello hello.c -lm -lgreet Jul 01 00:40:02 _pjp_, the compilation Jul 01 00:40:05 i also tried -llibgreet Jul 01 00:40:10 even that does not Jul 01 00:40:14 <_pjp_> Excellent..that's where -L comes handy Jul 01 00:40:16 i too tried that Jul 01 00:40:21 mavu_, not supposed to Jul 01 00:40:35 gives a pages full of warnings and errors Jul 01 00:40:59 <_pjp_> What happened was, gcc could not find our greet library in the predefined search path. Jul 01 00:41:39 -L works :) Jul 01 00:41:40 <_pjp_> so now we explicitly tell gcc where to find it. Jul 01 00:42:13 <_pjp_> so just say: $ gcc -x c -ansi -I ./ -L ./ -o hello hello.c -lm -lgreet Jul 01 00:42:39 <_pjp_> did that work for everone Jul 01 00:42:40 <_pjp_> ? Jul 01 00:42:45 <_pjp_> everyone? Jul 01 00:43:09 done Jul 01 00:43:17 yes, it did Jul 01 00:43:28 * t4num0y_cs3 has quit (Read error: 104 (Connection reset by peer)) Jul 01 00:43:30 ! Jul 01 00:43:36 done Jul 01 00:43:38 <_pjp_> ria, ? Jul 01 00:43:41 working Jul 01 00:43:42 <_pjp_> deepak, great! Jul 01 00:43:46 no,there is the same error Jul 01 00:43:49 why is it -lgreet? Jul 01 00:43:54 _pjp_, ^^ Jul 01 00:44:28 <_pjp_> -l tells gcc that it is a library, and greet is the name of our library Jul 01 00:44:40 ! Jul 01 00:44:42 <_pjp_> susenj, what did you do? Jul 01 00:44:43 is it not libgreet? Jul 01 00:44:57 i tried : gcc -x c -ansi -I ./ -L ./ -o hello hello.c -lm -lgreet Jul 01 00:45:09 <_pjp_> ria, yes that's a filename. lib is optional. Jul 01 00:45:20 ok _pjp_ Jul 01 00:45:25 Jul 01 00:45:29 <_pjp_> and what's the error? Jul 01 00:45:32 <_pjp_> susenj, ? Jul 01 00:46:01 pages full of errors,uncountable Jul 01 00:46:30 <_pjp_> susenj, could you paste it? Jul 01 00:46:31 ! Jul 01 00:46:37 <_pjp_> deepak, ? Jul 01 00:46:46 ok Jul 01 00:46:58 here lgreet is an option Jul 01 00:47:32 here is lgreet is an option ? Jul 01 00:47:51 <_pjp_> deepak, -l is an option combined with library name. Jul 01 00:48:18 <_pjp_> deepak, library name changes, see -lm Jul 01 00:48:46 _pjp_; http://rafb.net/p/vy2lCS19.html Jul 01 00:49:39 <_pjp_> susenj, what is in your hello.h file? Jul 01 00:51:26 <_pjp_> susenj, ? Jul 01 00:51:33 when i tried: cat hello.h ,it gives garbage,i don't know why. Jul 01 00:52:09 <_pjp_> susenj, he..he..you messed up the hello.h file. check you command history. Jul 01 00:52:17 :) Jul 01 00:52:47 ok,let me do that,you may continue Jul 01 00:53:25 <_pjp_> okay, so folks what we did was Jul 01 00:54:25 <_pjp_> We did create our own static library containing function greet () and link it with the hello.c program where we did call greet() function. Jul 01 00:55:19 <_pjp_> And we also did instruct gcc about where to look for our library for linking. Jul 01 00:56:21 <_pjp_> You can use gcc option -I to specify include directory, and -L to specify library directory. Jul 01 00:57:02 <_pjp_> I think now we can go for questions for today? Jul 01 00:57:05 <_pjp_> kushal, ? Jul 01 00:57:11 yes Jul 01 00:57:36 everyone ask Jul 01 00:57:38 :) Jul 01 00:57:40 with ! Jul 01 00:58:15 ! Jul 01 00:58:18 d! Jul 01 00:58:23 !* Jul 01 00:58:25 <_pjp_> deepak, yes? Jul 01 00:58:32 <_pjp_> mavu_, ? Jul 01 00:58:53 what is the difference btw a notmal #include and this process? Jul 01 00:59:00 as in yeah i see the difference Jul 01 00:59:16 but why should there be 2 methods of including code from external Jul 01 00:59:18 file? Jul 01 00:59:22 _pjp_:please make me clear this -lm option Jul 01 00:59:44 * nandy_lost_ has quit ("ChatZilla 0.9.83 [Firefox 3.0/2008052906]") Jul 01 00:59:51 <_pjp_> mavu_, #include only provides the declarations for functions, where as libraries have actual definitions of those functions. Jul 01 01:00:19 deepak, we are using sqrt function which is a part of math library Jul 01 01:00:23 <_pjp_> mavu_, header files do not have function definitions, as in the function code. Jul 01 01:00:31 but in our previous codes.. we always just did a #include math.h Jul 01 01:00:36 deepak, so we have to add that library for linking Jul 01 01:00:40 #include Jul 01 01:00:49 kushal:so we use -lm m for math.h Jul 01 01:00:51 <_pjp_> mavu_, and we also linked with -lm Jul 01 01:01:06 that was because we used a -c Jul 01 01:01:09 deepak, not for, but you have to use both to use sqrt function Jul 01 01:01:10 as in Jul 01 01:01:15 if we don't use -c Jul 01 01:01:24 and a normal gee filename Jul 01 01:01:26 <_pjp_> deepak, math.h has declaration for sqrt, see: less /usr/include/math.h Jul 01 01:01:26 gcc Jul 01 01:01:27 * Jul 01 01:01:31 <_pjp_> mavu_, ? Jul 01 01:01:58 the very first command you gave us Jul 01 01:02:02 _pjp_:-l is for linking but what m is for Jul 01 01:02:16 * samar has quit ("Ex-Chat") Jul 01 01:02:18 gcc 1 step one Jul 01 01:02:22 ! Jul 01 01:02:23 deepak, name of the math library Jul 01 01:02:23 after which we called Jul 01 01:02:28 a.out Jul 01 01:02:29 susenj, yes please Jul 01 01:02:32 i am confused Jul 01 01:02:34 like for some math functions,we have to link with math library,why not this linking is for printf()/scanf() like i/o functions? Jul 01 01:02:42 <_pjp_> deepak, gcc understands m for maths, as it's part of the standard library. Jul 01 01:02:53 <_pjp_> susenj, ? Jul 01 01:03:06 like for some math functions,we have to link with math library,why not this linking is for printf()/scanf() like i/o functions? Jul 01 01:03:06 susenj, printf, scanf are part of standard C library , libc, which is included by default Jul 01 01:03:27 _pjp_:-lgreet here greet is library Jul 01 01:03:30 <_pjp_> susenj, I/O library is automatically linked with every program. Jul 01 01:03:34 ! Jul 01 01:03:39 <_pjp_> Debashree, ? Jul 01 01:03:41 <_pjp_> ria, ? Jul 01 01:03:48 ok.thanks! got that Jul 01 01:04:07 like -lm is for maths link can you give examples of some other links? Jul 01 01:04:33 i mean after -l Jul 01 01:04:40 ria, -lxml Jul 01 01:04:41 Jul 01 01:04:44 ria, -lrfid Jul 01 01:04:57 -lyahoo Jul 01 01:05:05 ok Jul 01 01:05:08 <_pjp_> ria, there hundreds of external libraries like: -lncurses for new curses, or -lpcap for packet capture library etc. Jul 01 01:05:08 ^^ above for lib yahoo Jul 01 01:05:27 ok thanks Jul 01 01:05:30 Jul 01 01:05:33 <_pjp_> deepak, ? Jul 01 01:05:49 _pjp_:-lgreet here greet is library Jul 01 01:05:58 deepak, correct Jul 01 01:06:03 ! Jul 01 01:06:32 <_pjp_> deepak, yes, it's an archive file containing greet.o, which contains the object code for function greet () Jul 01 01:06:41 <_pjp_> mavu_, ? Jul 01 01:07:00 what i wanted to ask is.. if i remove all references of hello.h and greet().. a basic hello world program with a sqrt() Jul 01 01:07:02 * Debashree_ (n=Debashre@61.2.164.178) has joined #dgplug Jul 01 01:07:04 then i did Jul 01 01:07:06 [satsiv@localhost ~]$ gcc hello.c Jul 01 01:07:07 [satsiv@localhost ~]$ a.out Jul 01 01:07:16 it works Jul 01 01:07:28 $./a.out Jul 01 01:07:38 $ ./a.out Jul 01 01:07:41 sorry* Jul 01 01:07:45 this works Jul 01 01:07:46 _pjp_:but you were talking about library Jul 01 01:07:58 here if i don't use a -c.. Jul 01 01:07:59 <_pjp_> mavu_, yes, I did tell yesterday that on some machines maths library is also linked by default. Jul 01 01:08:27 ah okay.. so is that not standard? Jul 01 01:08:36 <_pjp_> deepak, yes, archive is collection of one or more files, i.e library. Jul 01 01:09:02 _pjp_:ok Jul 01 01:09:16 koay :) thanks Jul 01 01:09:25 okay* sorry for my typos Jul 01 01:09:26 ! Jul 01 01:09:40 <_pjp_> mavu_, yes, it is. But it also depends on Linux distribution you are using. Jul 01 01:09:49 <_pjp_> pushkal, ? Jul 01 01:09:58 pushkal, Jul 01 01:09:59 _pjp_: does the library have the *.o files only ? Jul 01 01:10:11 <_pjp_> pushkal, yes. Jul 01 01:10:25 ok.. thanks Jul 01 01:12:14 <_pjp_> is that all? Jul 01 01:13:07 _pjp_:ok Jul 01 01:13:12 <_pjp_> okay then, good night guys! :) Jul 01 01:13:21 <_pjp_> and girls too! :) :) Jul 01 01:13:21 _pjp_:good night Jul 01 01:13:24 good night _pjp_ ! thanks for a wonderful class ! Jul 01 01:13:25 good night and thanks :) _pjp_ Jul 01 01:13:28 _pjp_, thanks Jul 01 01:13:30 Good Night all Jul 01 01:13:34 good night :) Jul 01 01:13:34 <--CLASS OVER -->