Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, as a beginner, you should always ask GCC to compile with all warnings and debugging information enabled, i.e. <code>gcc -Wall -g</code> </p> <p>Then you are probably missing some Harvard specific library, some options like <code>-L</code> followed by a library directory, then <code>-l</code> glued to the library name. So you might need <code>gcc -Wall -g -lcs50</code> (replace <code>cs50</code> by the appropriate name) and you might need some <code>-L</code><em>some-dir</em> </p> <p>Notice that the order of program arguments to <code>gcc</code> is significant. As a general rule, if <code>a</code> depends upon <code>b</code> you should put <code>a</code> before <code>b</code>; more specifically I suggest</p> <ol> <li>Start with the <code>gcc</code> program name; add the <em>C</em> standard level eg <code>-std=c99</code> if wanted</li> <li>Put compiler warning, debugging (or optimizing) options, eg <code>-Wall -g</code> (you may even want to add <code>-Wextra</code> to get even more warnings).</li> <li>Put the preprocessor's defines and include directory e.g. <code>-DONE=1</code> and <code>-Imy-include-dir/</code> </li> <li>Put your <em>C</em> source file <code>hello.c</code> </li> <li>Put any object files with which you are linking i.e. <code>bar.o</code> </li> <li>Put the library directories <code>-Lmy-lib-dir/</code> if relevant</li> <li>Pur the library names <code>-laa</code> and <code>-lbb</code> (when the <code>libaa.so</code> depends upon <code>libbb.so</code>, in that order)</li> <li>End with <code>-o your-program-name</code> to give the name of the produced binary. Don't use the default name <code>a.out</code> </li> </ol> <p>Directory giving options <code>-I</code> (for preprocessor includes) and <code>-L</code> for libraries can be given several times, order is significant (search order).</p> <p>Very quickly you'll want to use builder tools like <code>make</code> </p> <p>Learn also to use the debugger <code>gdb</code> </p> <p>Get the habit to always ask for warnings from the compiler, and always improve your program till you get no warnings: the compiler is your friend, it is helping you!</p> <p>Have fun.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload