How can I configure the CS50 library in Geany without keeping it in the same folder?

0
3
Asked By TechGuru99 On

I've just started the CS50x course and I'm trying to set up the CS50 library in my IDE, which is Geany. Currently, everything works fine as long as the libcs50.dylib file is in the same folder as my test.c file. However, I'd prefer to keep all libraries in a single location to avoid clutter. I've attempted to adjust the build command to locate the library in a different directory, but it hasn't worked. Here's the build command I'm using:

gcc -Wall -L/Users/simonwiksell/Desktop/TEST/Libraries/lib -lcs50 -o "%e" "%f"

I created a Libraries folder inside the TEST folder for the cs50 installation path. While the compilation goes smoothly, I get an error while trying to run the program:

dyld[35326]: Library not loaded: libcs50-11.0.3.dylib

referenced from: /Users/simonwiksell/Desktop/TEST/test

reason: tried: 'libcs50-11.0.3.dylib' (no such file), ... (other paths)

So, I'm looking for help on how to fix this issue.

3 Answers

Answered By HelpfulCoder7 On

If you’re having trouble with changing the paths, I recommend keeping the library alongside your program while testing. Once you confirm it works, you can try setting up the environment variable as suggested.

Answered By CodeNinja42 On

You need to set the `LD_LIBRARY_PATH` environment variable, which tells your system where to find the dynamic libraries. To do this, you can add the library path to your shell configuration file, such as `.bash_profile` or `.zshrc`, depending on what shell you’re using. For example, you can add:

```bash
export LD_LIBRARY_PATH=/Users/simonwiksell/Desktop/TEST/Libraries/lib:$LD_LIBRARY_PATH
```

After saving the file, don't forget to restart your terminal or run `source ~/.bash_profile` (or the appropriate file) to apply the changes.

Answered By DevWizard84 On

That build command looks fine, but since you're using Mac, you might want to check if the library is set in the correct path that your system can access. You can also try using the `install_name_tool` command to change the library's install path after you compile your program.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.