GithubHelp home page GithubHelp logo

cs50-minimal-setup's Introduction

CS50 Minimal Setup for macOS and Linux

Prerequisites

This guide assumes that:

Getting started

Before starting, make sure that you are in the project directory containing test.c (or some C code to compile).

First, clone the libcs50 git repository:

git clone https://github.com/cs50/libcs50.git

Then, your project directory will be like (ommitted unnecessary ones):

$ tree
.
├── README.md
├── build.sh
├── libcs50
│   ├── LICENSE
│   ├── Makefile
│   ├── README.md
│   ├── src
│   │   ├── cs50.c
│   │   └── cs50.h
│   └── tests
└── test.c

cd into the cloned directory (libcs50) and build:

cd libcs50
make

Then, your build directory will be like:

$ cd build
$ tree
.
├── include
│   └── cs50.h
├── lib
│   ├── libcs50-11.0.2.dylib
│   ├── libcs50.a
│   └── libcs50.dylib -> libcs50-11.0.2.dylib
└── src
    └── cs50.c

To build a C program, you need cs50.h and either libcs50-11.0.2.dylib (for Dynamic Linking) or libcs50.a (for Static Linking).

Option 1. Dynamic linking

Place libcs50-11.0.2.dylib in your CS50 project directory. The contents of the project directory will look like:

$ ls
cs50.h        test.c        libcs50-11.0.2.dylib

Build test.c as follows:

cc -o test test.c -lcs50

Option 2-1. Static linking

Place libcs50.a in your CS50 project directory. The contents of the project directory will be:

$ ls
cs50.h        test.c        libcs50.a

Build test.c as follows:

cc -o test test.c libcs50.a

Option 2-2. Static linking - Using flags to link libraries

Use the following flags in your compile command:

  • -I for include path.

Build test.c as follows:

cc -o test test.c -I./libcs50/build/include ./libcs50/build/lib/libcs50.a

For an enhanced version, see Build Script.

Running the program

After building, you can run the test binary file with:

./test

Why?

  1. A minimal setup will lower the barrier to C programming.
  2. You don't want to mess up the system's lib directory with a library that will never be reused.
  3. In macOS, there are some problems with dyld (Dynamic Link Editor). For example, if you have disabled SIP (System Integrity Protection), you might encounter issues when following the methods described in official guides.

References

See also

cs50-minimal-setup's People

Contributors

lentil32 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.