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.
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:
Dowload cs50 library from: http://mirror.cs50.net/library50/c/library50-c-5.zip
Copy cs50.c and cs50.h into the pset directory.
Set up your environment as follows:
export CC=clang
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror -lcs50 -lm -I. cs50.c"
Run: make [program name]
Don't tell CS50 folks I showed it to you ;)
-
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 -
-
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
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.
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