3

I want to change the default options of make to be like the appliance one. I have installed clang and the cs50.h library but right now I compile the programs using clang hello_world.c -lcs50 -o hello_world for example. It would be nice if you can explain each command that should be included. The appliance one uses clang -ggdb3 -00 -std=c99 -Wall -Werror -argv-2.c -lcs50 -lm -o argv-2.

4
  • What do you mean? Your question is what is very little things such as -Wall means? – RexYuan Oct 26 '14 at 3:47
  • My question is how do I do for make to do the same as this line: clang -ggdb3 -00 -std=c99 -Wall -Werror -argv-2.c -lcs50 -lm -o argv-2 – ajr-dev Oct 26 '14 at 7:17
  • What's your operating system? – kzidane Oct 26 '14 at 10:51
  • The operating system is Kubuntu – ajr-dev Oct 27 '14 at 18:26
5

In Linux you can do:

export CC=clang
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror -lcs50 -lm"

and then run:

make argv-2

I don't use Windows, but I believe it uses set instead of export.

NB: If you want to be able to compile your psets without installing the appliance or the cs50 library, you can do this:

  1. Dowload cs50 library from: http://mirror.cs50.net/library50/c/library50-c-5.zip

  2. Copy cs50.c and cs50.h into the pset directory.

  3. Set up your environment as follows:

    export CC=clang

    export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror -lcs50 -lm -I. cs50.c"

  4. Run: make [program name]

  5. Don't tell CS50 folks I showed it to you ;)

5
  • I got this: $ make hello clang -ggdb3 -O0 -std=c99 -Wall -Werror -lcs50 -lm hello.c -o hello /tmp/hello-c048b1.o: In function main': /home/arturo/Desktop/hello.c:7: undefined reference to GetString' clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [hello] Error 1 – ajr-dev Oct 27 '14 at 18:28
  • How can I return clang to default when I do this experiments? – ajr-dev Oct 27 '14 at 18:29
  • It's not finding the cs50 library, which is why it's complaining about the GetString function. Where and how did you install the cs50 lib? – Hedgehog Oct 27 '14 at 20:35
  • It was almost as you said thank you :) How would I do when I want to put make as default? – ajr-dev Oct 27 '14 at 21:39
  • You mean to make them persistent? Check this: help.ubuntu.com/community/EnvironmentVariables – Hedgehog Oct 27 '14 at 22:21
4
export CC=gcc
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror"
export LDLIBS="-lcs50 -lm"

-ggdb

       Produce debugging information for use by GDB.  This means
       to use the most expressive format available (DWARF 2,
       stabs, or the native format if neither of those are
       supported), including GDB extensions if at all possible.

-ggdblevel

       Request debugging information and also use level to specify
       how much information.  The default level is 2.

       Level 3 includes extra information, such as all the macro
       definitions present in the program.  Some debuggers support
       macro expansion when you use -g3.

-O0

       Reduce compilation time and make debugging produce the
       expected results.  This is the default. (Is a optimization option)

-Wall

       Turns on all optional warnings which are desirable for
       normal code.  At present this is -Wcomment, -Wtrigraphs,
       -Wmultichar and a warning about integer promotion causing a
       change of sign in "#if" expressions.  Note that many of the
       preprocessor's warnings are on by default and have no
       options to control them.

-Werror

       Make all warnings into hard errors.  Source code which
       triggers warnings will be rejected.

-lm

       possibly loads a math library.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .