3

Is there any way I can download and install the CS50 library to my system and run programs importing the library instead of downloading the virtual machine ?

8

Here are the instructions for installing CS50 library in your OS:

Linux

  • First become root, as with:

    su -  // Fedora, RedHat, CentOS
    sudo -s  // Debian, Ubuntu, Mint //edited from sudo su -,  use sudo -s on Ubuntu.
    
  • Then install the CS50 Library as follows:

    yum -y install gcc  // Fedora, RedHat, CentOS
    apt-get install gcc  // Debian, Ubuntu, Mint
    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
    

For those lucky fellows running Linux, there's this reddit explaining how to make Linux Mint "CS50 compatible" (i.e.: installing clang, check50, and cs50 libraries for Python, Ruby and PHP)


Mac OS

  • Download and install Xcode.

  • Download and unzip library50-c-5.zip.

  • Open Applications > Utilities > Terminal, and navigate your way to the CS50 Library‚Äôs directory, as with cd.

  • Execute the commands below, entering your password if prompted:

    gcc -c -ggdb -std=c99 cs50.c -o cs50.o
    ar rcs libcs50.a cs50.o
    rm -f cs50.o
    chmod 0644 cs50.h libcs50.a
    sudo mkdir -p /usr/local/include
    sudo mv -f cs50.h /usr/local/include
    sudo mkdir -p /usr/local/lib
    sudo mv -f libcs50.a /usr/local/lib
    cd ..
    rm -rf library50-c-5
    

Windows

It depends on your compiler, but odds are the simplest method of installation is to:

  • Download and unzip library50-c-5.zip.

  • Copy cs50.c and cs50.h into the same directory as your own code.

After installing the CS50 Library, you can include its header file atop your own code with:

#include "cs50.h"

Note the use of quotes instead of angled brackets.

| improve this answer | |
  • With these Mac OS instructions I've run into problems. I'm on OSX Sierra. How do I download and install cs-50 library and x-code. Can you explain from where I download the files and how to do this without the use of Sudo or wget. My Mac terminal doesn't understand Sudo. – Android1 Mar 15 '17 at 7:48
  • I've followed these instructions and all seemed to have gone smoothly. But when I executed my test code with 'make test01.' I got this as an error message: cc test01.c -o test01 test01.c:2:10: fatal error: 'cs50.h' file not found #include "cs50.h" ^~~~~~~~ 1 error generated. make: *** [test01] Error 1 Anything else I could do to make this work? – SUPERSANE Sep 17 '19 at 2:16
4

An easier method is to use my CS50 tools setup if you're on Ubuntu or Fedora. Open a terminal in your download directory, and run

sudo sh cs50_setup_ubuntu.sh

or

sudo sh cs50_setup_fedora.sh

depending which OS you're on

Download the file here:

Ubuntu (and Ubuntu derivative, such as Linux Mint etc): https://www.dropbox.com/s/6wv06ejnw7ryqf6/cs50_setup_ubuntu.sh?dl=0

Fedora (and Fedora derivative, such as Red Hat etc): https://www.dropbox.com/s/qn3dedqznxem9vt/cs50_setup_fedora.sh?dl=0

Use

make50

to compile the program and

check50

to check it.

| improve this answer | |
  • Cool! I'm not versed in bash, so had to transcript the whole thing ;) BTW: why don't you start with sudo su -? does #bash do that automagically for you? is it necessary at all? (or you just forgot =P) – abelinux Jan 13 '15 at 18:49
  • 1
    No I'm not very well versed either, but I like creating files that run code for me (like batch in windows) rather than having to run each command magically. It was even more of a pain in windows, because before Win10 Tech Preview, I had to use a clunky AHK script to paste into the command prompt. .sh files just run each command in the terminal like a .bat would. And about sudo, you could do that, but I like using one line to run. Prefacing the sh with sudo runs every command in sudo. – pythonhax Jan 13 '15 at 20:28
1

There is also instructions in the Github repo.

But ensure to install rubygems before running gem install asciidoctor

| improve this answer | |
0

Here's a video for adding the CS50 library for Codeblocks IDE in Windows It's similar to one @abelinux mentioned but sets it up for all projects instead of having to add it individually to each project: CS50 Library on Windows CodeBlocks IDE

There's also a small gotcha with the get_string method which it helps sidestep if you are facing issues with improper arguments or too few arguments error when trying to use it.

| improve this answer | |
0

If using Linux and you want to install the CS50 Library from source, follow these steps: - Go to https://github.com/cs50/libcs50/releases - Download the latest release of the library (file that ends in .tar.gz) - Navigate to downloaded file - Extract the contents to a folder - Navigate to the above folder - run sudo make install

That is all. Worked well for me.

| improve this answer | |

You must log in to answer this question.

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