Hot answers tagged

16

This is a very common question asked by new students. The make command is used to compile the source code and generate an executable program. While there are complexities to this process (more explanation in later lessons), this answer will give a simple 'how-to' for the early lessons so that you can get started. To use make to build your executable, the ...


8

You are most probably doing make whodunit.c which should be make whodunit I also often get confused with these. So there is a way to think for it, always remember, you want to create executable that's why you write make whodunit, you don't want to create whodunit.c(ofc you are the one who is going to write it and not the computer), so you don't write ...


5

Two ways to configure make to execute a specific compilation command with specific options are: Makefiles 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 ...


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: Dowload cs50 library from: http://mirror....


4

When run without a makefile, Make takes its cues from environment variables set in your shell (specifically, those loaded in /etc/profile.d/appliance50.sh). To get the same behavior from Make as it has in the CS50 Appliance, you can add the following to your .bashrc (or .zshrc, etc, if you're using a different shell): export CC=clang export CFLAGS="-...


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


3

If there's no Makefile in the same directory as the program that you're trying to compile, make uses its default configuration. In the appliance, make uses some environment variables to run the compilation command that you see on .c files. For more information about these variables, see Variables Used by Implicit Rules!


3

Take a look at the terminal window, are you inside Dropbox/pset1?


3

Looking at the screen capture, I would say that hello doesn't compile because you are not in the directory that contains hello.c. It would appear that you are trying to execute the make hello command in ~/workspace/pset1 but hello.c resides in ~/workspace. Try moving the hello.c file to the pset1 directory. If this answers your question, please click on ...


2

You should first navigate to the directory where hello.c exists then just run make hello!


2

First, .h files are not libraries. Rather, they're libraries' header files. More on that here! The string library, as @Hassan Javed said, is part of the C standard library. And it's linked by default. Libraries that are not part of the C standard library (e.g., the cs50 library) need to be linked manually with the -l flag.


2

Make sure the file named adder has the extension .c. Also make sure you're executing this command make adder NOT make adder.c


2

The makefile can be confusing at times because a lot of the steps are left out for simplicity sakes, and implied by make using default behaviour. It might make a bit more sense if you manually replace the variables (OBJS and HDRS) with their "expanded" values, e.g.: # automatically generated list of object files # OBJS = $(SRCS:.c=.o) OBJS = speller.o ...


2

the command/file name combination is case sensitive - make sure you have named your file "hello" rather than "Hello". If it's capitalised, try "make Hello"


2

cs50.h is a header file. Header files are NOT linked. They are included. What is linked is a library binary file. If you have successfully installed the cs50 library according to the instructions here, then follow these steps to link it by default when executing make open up a terminal window (Ctrl + Alt + T) change directories to your home directory by ...


1

you are not in the correct directory, you must move to .c9 doing: cd .c9 your terminal should look similar to ~/workspace/.c9/ $ then you can do: make hello and then run the program with ./hello


1

If you type make filename, it will indeed look for a file called filename.c, unless it has instructions in a makefile (named makefile, more in later lessons) to do something different. Whatever filename is, it will look for a file with that name, followed by .c. Now, if you make the mistake of trying to make foobar.c, it will choke. The .c in the make ...


1

This answer did not work for me at all. There IS a file called mario in my directory. I AM on the directory mario. I try to compile and I get the same error this person did and apparently there is NOTHTING I can do to solve it. I've been digging for hours. Something is wrong.


1

are you trying make greedy.c ? if yes, try this; make greedy


1

This problem was most likely caused by the original make compilation settings in the Appliance. A simple update50 command fixed it, as the poster noted in a comment to the original post. The for loop syntax that we learn in CS50, an example of which is included below, is defined in the C99 standard for the C programming language. for (int i = 0; i < 10; ...


1

I run update50 on the terminal and the problem was resolved :D


1

If you haven't already, run update50. There's a bug in the built-in-terminal in gedit that this fixes. Alternatively, use the standalone Terminal app rather than the one in gedit, as that works fine.


1

I can assume that you have broken or not set CFLAGS and LDLIBS environment variables. In the same folder try to create a file called makefile and place the next lines inside it: CC=clang CFLAGS=-ggdb3 -O0 -std=c99 -Wall -Werror LDLIBS=-lcs50 -lm Then just call make: make getname for ABC ;)


1

I solved the cs50.h problem by updating my appliance. For updating open the terminal in the appliance and type-- update50 After the process is completed, cs50.h will work..


1

You never linked the CS50 library binary file to your program using the -lcs50 option on compilation!


1

When run without a makefile, Make takes its cues from environment variables set in your shell (specifically, those loaded in (specifically, those loaded in /etc/profile.d/appliance50.sh). To get the same behavior from Make as it has in the CS50 Appliance, you can add the following to your .bashrc (or .zshrc, etc, if you're using a different shell): export ...


1

Is this a serious problem whenever I use these programs? Why might the programmers who wrote these programs ignore the advice about preventing memory leaks? Check out the top Google result for the search phrase "valgrind ls leaks". It's a bug report made to the GNU project's bug-coreutils mailing list back in 2011 that makes essentially the same claim (...


1

I used VirtualBox under linux Ubuntu 14.04 without hardware virtualization, and switched to HAV only some days after I started the course. You should be able to access Internet without HAV. On this link you'll find a way to run CS50 library from your Linux distro.


1

I wasn't using Dropbox, but I got the same error. I discovered that I had named the source code file conditions-0 instead of conditions-0.c. The compiler doesn't know what to do without the .c extension.


1

As @lethaljd has pointed out, make sure you're in the same directory as the file named conditions.c then execute make conditions You can change directories using the cd command. Also, the produced executable should be named conditions NOT ./conditions.0 unless specified otherwise.


Only top voted, non community-wiki answers of a minimum length are eligible