0

so , i'm not using CS50 Appliance

The problem i have is , i get this GetString error when i use "make" command in terminal (everything works fine when i Directly use Clang or Gcc ).

I know i have to update my cs50 Library (since the solution to this problem is to update the cs50 appliance ) . if someone could please update thease command for me it would be awesome .

" Debian, Ubuntu

First become root, as with:

sudo su -

Then install the CS50 Library as follows:

apt-get install gcc 
wget http://mirror.cs50.net/library50/c/library50-c-5.zip 
unzip library50-c-5.zip
rm -f library50-c-5.zip
cd library50-c-5
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf library50-c-5  " 

Also , if someone could please explain to me why i cant map my "CTRL-Backspace " to Deleting the Last word in vim . i have tried everything google could offer me .

  • What are you trying to do exactly and what is the exact error that you are getting? – Kareem Mar 22 '15 at 18:06
  • are you including the cs50 libraries in your includes statements and do you have them saved locally to access? You can always download the string.h library somewhere from Google and that should work for you. – lethaljd Mar 23 '15 at 16:34
  • When i try to compile my code with "make " command in terminal i get this error : cc entername.c -o entername /tmp/ccMvsTgg.o: In function main': entername.c:(.text+0x18): undefined reference to GetString' collect2: error: ld returned 1 exit status make: *** [entername] Error 1 – sadhu_sanju Mar 25 '15 at 4:48
1

You don't need to update the cs50 library, your problem is that your make command is using the default implicit rules to determine what to do when there is no makefile, then when the action is determined it uses the content of make's predefined variables to execute a determined command. And this default command is not linking the cs50 library.

I think in the appliance this variables or the implicit rules are modified by the cs50 staff to change de default compiler and arguments that make uses for .c files. If you want to use make like in the appliance you'll have to learn how to edit the implicit rules, or the variables called by this rules, i don't know how to do this but you can take a look to the gnu make manual if you are determined to do it.

But other easiest solution would be to create an alias to call make with the compiler and arguments used in cs50 appliance by default. To do this, you need to create a file named.bash_aliasesin your user's home directory if you don't have one already.

Just type this:

gedit ~/.bash_aliases 

then add this line at the bottom and save the file.

alias makes='make CC=clang CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror" LDLIBS="-lcs50 -lm"'

now you can use makes instead of make and it should compile like in the cs50 appliance, for example to compile a file called hello.c:

makes hello

Edit: forgot to mention that you need to run this in a new terminal to reload the .bash_aliases file once saved.

| improve this answer | |
0

You just have to go to your terminal window and type these commands

sudo apt-get install cmake

Basically this will install make cmake for you with which you can use "make" command in terminal.

I'm 98% sure this will solve the problem granted your problem looks like mine .

  and also, I found the answer after 2 months while working on totally different problem. 

-- keep coding

| improve this answer | |
0

What you want to do, is create a custom Makefile. A Makefile is a file you have inside the same directory with your source code, that gets executed when you are in that directory, you run make something and that something is a target specified inside the Makefile. Let's see how to create such a file.

Start by specifying the compiler yo use, in your case clang.

CC = clang

Then the flags to pass the compiler. Those used in CS50 are:

CFLAGS = -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror

Then the name of the executable to be created.

EXE = greedy

Then a space separated list of all the headers your program will use (none in your case).

HDRS = 

Then a space separated list of all the libraries your program will use.

LIBS = -lcs50 -lm

Then a space-separated list of C files that will collectively implement your program.

SRCS = greedy.c

Then the same list in SRCS but instead of .c with .o.

OBJS = $(SRCS:.c=.o)

Then the target line, where you specify what will happen exactly when the command is given.

$(EXE): $(OBJS) $(HDRS) Makefile
    $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

Then the files that your .o files "depend on".

$(OBJS): $(HDRS) Makefile

And then a command for housekeeping, that will remove any core, compiled and .o files you have in the folder by previous compilations or runs.

clean:
    rm -f core $(EXE) *.o

Keep in mind that the indentations in the commands, are tab characters and not spaces. So make sure your editor doesn't change the tabs into spaces automatically as many do.

So your final file (Called Makefile) must look something like this:

CC = clang

CFLAGS = -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror

EXE = greedy

HDRS = 

LIBS = -lcs50 -lm

SRCS = greedy.c

OBJS = $(SRCS:.c=.o)

$(EXE): $(OBJS) $(HDRS) Makefile
    $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

$(OBJS): $(HDRS) Makefile

clean:
    rm -f core $(EXE) *.o

If you want to make a Makefile for another project just change the parameters that change. You can learn more about Makefiles here: http://cdn.cs50.net/2015/x/psets/5/pset5/pset5.html#makefile. If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark.

[I should note that I posted this late answer as I didn't like very much @wallek876 's solution with the aliases. It could also be a reference for how to create a Makefile as I haven't seen one here.]

| improve this answer | |
  • @saicharannivarthi take a look at that if you visit this page. – ChrisG Aug 15 '15 at 7:56
  • 1
    Maybe you don't like it, but it is very handy because when you have the alias created you can call it whenever you need, and with the makefile you have to move it around and update it for every new file you want to target. – wallek876 Aug 15 '15 at 8:31
  • Sure! I didn't mean to offend you. It's a perfect solution. It's just me that I don't like so universal solutions. I want to specify with detail what I need. For example what if I don't need the math library in a program? – ChrisG Aug 15 '15 at 8:35
  • Of course if don't use you don't need to link it. The alias is just to match the behaviour of make in the appliance that links the math library by default. – wallek876 Aug 15 '15 at 8:51

You must log in to answer this question.

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