1

When executing

make prog

in the same directory as my source code file named prog.c, I see this command gets executed

gcc prog.c -o prog

which leads to causing various compile-time errors from being not able to use for loops to undefined reference to the functions of the cs50 library.

How to fix this?

  • 1
    It's a bug in the appliance. the built-in terminal in gedit is not using the cs50 make file. Run update50. or, open a separate terminal window and run make there. – curiouskiwi Jan 9 '15 at 10:32
5

Two ways to configure make to execute a specific compilation command with specific options are:

  1. Makefiles
  2. Environment Variables

Assuming you have a source code file of a C program named prog.c, to manually configure make to execute the same compilation command as the one in the lectures follow either of the following ways:

Configuring make Using Makefiles

  1. create a file named Makefile in the same directory as your program and paste the following text in it

    prog: prog.c
        clang -ggdb3 -O0 -std=c99 -Wall -Werror prog.c -lcs50 -lm -o prog
    

NOTE: the second line starts with a tab not spaces

  1. save the file.

Configuring make Using Environment Variables

Two ways of achieving this are

  1. temporarily setting the values of some environment variables
  2. permanently setting the values of these environment variables.

Configuring make Temporarily

Open up a terminal window and execute these commands

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

Configuring make Permanently

  1. Open up the terminal window and execute these commands

    cd
    sudo gedit .profile
    

NOTE: if asked to enter a password, enter "crimson"

  1. paste the following lines at the end of the file

    export CC="clang"
    export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror -Wno-unused-variable"
    export LDLIBS="-lcs50 -lm"
    
  2. log off and log back in

| improve this answer | |

You must log in to answer this question.

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