Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dyld troubleshoot for newer macs; addresses libcs50 issue 331 #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions libraries/cs50/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Ubuntu
-------

.. code-block:: bash

$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash
$ sudo apt install libcs50


Fedora
-------
.. code-block:: bash
.. code-block:: bash

$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.rpm.sh | sudo bash
$ dnf install libcs50
Expand All @@ -32,13 +32,15 @@ From Source (Linux and Mac)
3. ``cd libcs50-*``
4. ``sudo make install``

By default, we install to ``/usr/local``. If you'd like to change the installation location, run ``sudo DESTDIR=/path/to/install make install`` instead.


Environment Variables
=====================

For parity with `Visual Studio Code for CS50 </code/>`_ and `cli50 <cli50/>`_, you may want to set these environment variables:

.. code-block:: bash
.. code-block:: bash

CC="clang"
CFLAGS="-ferror-limit=1 -gdwarf-4 -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-gnu-folding-constant -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable -Wshadow"
Expand All @@ -59,11 +61,11 @@ Alternatively, if using a ``Makefile`` to compile a program (e.g., ``foo``) from

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


$(EXE): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS)



Usage
Expand All @@ -83,7 +85,7 @@ Usage


.. function:: char get_char(const char *format, ...)

:param format: the :func:`printf`-like format string used to display the prompt
:param ...: values to be substituted into the format string a la :func:`printf`
:returns: the :code:`char` equivalent to the line read from stdin, or :macro:`CHAR_MAX` on error
Expand All @@ -92,7 +94,7 @@ Usage
if text does not represent a single char, user is reprompted.

Example usage::

#include <stdio.h>
#include <cs50.h>

Expand Down Expand Up @@ -120,7 +122,7 @@ Usage


.. function:: double get_double(const char *format, ...)

:param format: the :func:`printf`-like format string used to display the prompt
:param ...: values to be substituted into the format string a la :func:`printf`

Expand Down Expand Up @@ -157,7 +159,7 @@ Usage


.. function:: int get_int(const char *format, ...)

:param format: the :func:`printf`-like format string used to display the prompt
:param ...: values to be substituted into the format string a la :func:`printf`

Expand All @@ -170,8 +172,8 @@ Usage


#include <cs50.h>
...

...

// Returns the sum of two ints read from stdin, or INT_MAX if there was an error.
int add_ints(void)
Expand All @@ -197,7 +199,7 @@ Usage


.. function:: float get_float(const char *format, ...)

:param format: the :func:`printf`-like format string used to display the prompt
:param ...: values to be substituted into the format string a la :func:`printf`

Expand Down Expand Up @@ -233,7 +235,7 @@ Usage


.. function:: long get_long(const char *format, ...)

:param format: the :func:`printf`-like format string used to display the prompt
:param ...: values to be substituted into the format string a la :func:`printf`

Expand All @@ -245,8 +247,8 @@ Usage


#include <cs50.h>
...

...

// Returns the difference of two longs read from stdin, or LONG_MAX if there was an error.
long subtract_longs(void)
Expand Down Expand Up @@ -312,9 +314,22 @@ If when compiling your program, you see:

``/usr/bin/ld: cannot find -lcs50``:
Add ``export LIBRARY_PATH=/usr/local/lib`` to your ``.bashrc``.

``fatal error: 'cs50.h' file not found``:
Add ``export C_INCLUDE_PATH=/usr/local/include`` to your ``.bashrc``.

``cannot open shared object file: No such file or directory``:
Add ``export LD_LIBRARY_PATH=/usr/local/lib`` to your ``.bashrc``.


If when executing your program, you see something similar to (the following error is especially prevalent on newer Macs):

.. code-block:: bash

dyld[.....]: Library not loaded: libcs50-11.0.3.dylib
Referenced from: <.....> .....
Reason: tried: 'libcs50-11.0.3.dylib' (no such file), .....

Add ``export DYLD_LIBRARY_PATH=/usr/local/lib`` to your ``.bashrc``.

If you're not using Bash, use whatever command sets the value of environmental variables in your preferred shell. If you set ``DESTDIR`` to something other than ``/usr/local``, substitute it in for ``/usr/local`` in the suggestions above.