1

I'm taking the course of HarvardX: CS50x Introduction to Computer Science. Normally for doing this course you have to use a virtual machine for running a Fedora system called the cs50 appliance, with all the things made easy, but I already use Kubuntu so I downloaded clang and the cs50 library and I want to change the default options of make to include the library and stop when there are errors in the c program that I try to compile. In the appliance the make command does: clang -ggdb3 -00 -std=c99 -Wall -Werror -argv-2.c -lcs50 -lm -o argv-2. It would be nice if you can explain what should be included and why. When I compile a .c file using make, it doesn't load the cs50 library and I get: undefined function ...

I tried writing $ nano ~/.bashrc. Then went to the end of the file and put

 #CS50 alias for C compiling:
 alias makec='gcc -ggdb3 -std=c99 -Wall -Werror -argv-2.c -lcs50 -lm -o -argv-2'

Then $ source .bashrc

When I do $ makec hello now it says:

gcc: error: hello: No such file or directory
gcc: error: unrecognized command line option ‘-argv-2.c’

closed as off-topic by Panther, muru, Eric Carvalho, Sparhawk, αғsнιη Oct 26 '14 at 11:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Sparhawk, αғsнιη
If this question can be reworded to fit the rules in the help center, please edit the question.

  • can you clarify your question ? also this question is quite broad and it is unclear how this relates to ubuntu. – Panther Oct 25 '14 at 16:24
  • There are no "default" options for make. It does whatever you tell it do in your Makefile. Can you post the exact errors you're getting? – muru Oct 25 '14 at 19:55
0

What you need to do is related to the programs gcc and ld. Environment variables C_INCLUDE_PATH and LD_LIBRARY_PATH are places to search for headers and libraries respectively. The gcc options -l and -L are of use, it's usual to declare something like

LIBRARIES= -lcs

LIBDIR=-L/usr/local/lib

Then use these make-variables in the commands run by each rule. If you installed these libraries using apt-get there may be package config data available see command pkg-config

  • I don't know what the environment variables are. But anyway I'm able to compile .c source code doing gcc -ggdb3 -std=c99 -Wall -Werror hello.c -lcs50 -lm -o hello and I want to do the same doing make hello.c. – Arturo Oct 26 '14 at 7:49
  • Speak to your department's network admin to get an understanding of the basics like environmet variables. Buy the wrox book begining linux progra – rhubarbdog Oct 26 '14 at 12:09
  • ... programming. There's a wealth of knowledge in that. Commands like apropos, man and info will also help – rhubarbdog Oct 26 '14 at 12:11
0

I do not think this is solving your problem, but to answer the question as stated:

There are some ways to set default options for make:

  • Using a shell alias, like

    alias make='make --foo=bar'
    

    in ~/.bashrc or similar.

  • Setting the environment variable MAKEFLAGS to contain default options.

  • Using the environment variable MAKEFLAGS to add the default option -e (--environment-overrides), and define other variables relevant to the makefiles in ~/.bashrc, to be picked up by make, prioritized over definitions in the Makefile

With each of this methods, all uses of make are affected, which is not really what you want here.

A better solution seems to be to not change the default options of make,
but to use a separate alias to run make interactively. The alias can set options for recursive invocations of make.

alias cs50make='make --foo=bar'

or

alias cs50make='MAKEFLAGS="..." make'

or even

alias cs50make='MAKEFLAGS="-e ..." VAR1="..." VAR2="..." make'


Regarding making make stop on errors: It should normally do that by default, but if it's somewhere set to not stop, you can use the option -S (--no-keep-going, --stop) to override.

0

You 're make rule should read something like this,

hello : hello.c

gcc -ohello hello.c -g -lcs50 -lm

Now just type command

make hello

0
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.