How can I properly link the CS50 library in Geany on Mac?

0
3
Asked By CuriousCactus42 On

I'm currently taking the CS50x course and I'm trying to configure the CS50 library to work with Geany, my chosen IDE. Currently, everything functions well if the libcs50.dylib file is in the same directory as my test.c file. However, I'd like to keep all my libraries organized in a dedicated folder instead of duplicating them in every project. I attempted to adjust the build command to reference the library's new location but it hasn't worked out. Here's the build command I wrote:

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

I've created a 'Libraries' folder under 'TEST', which is where I indicated the library should be installed. Although the compilation runs without errors, when I try to execute my code, I encounter this error:

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

This indicates it's looking for the library in several locations but not succeeding. Any help on resolving this would be great!

2 Answers

Answered By DevChick88 On

Alternatively, you could try using the full path in your code when you link the library. Just make sure every program you've written knows where to find the library by using absolute paths. This can sometimes be a quick fix if setting `LD_LIBRARY_PATH` feels overly complicated.

CuriousCactus42 -

That's a good idea! I’ll give that a shot and see if it helps.

Answered By TechieTurtle37 On

You might want to set the `LD_LIBRARY_PATH` variable. This variable tells your system where to find the dynamic libraries when it can’t locate them in the usual paths. Try adding this command to your terminal before running your program:

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

After setting that, your compiled program should recognize where to find the CS50 library.

CuriousCactus42 -

Thanks for the tip! How exactly do I add that command to the terminal? Do I just type it in each time I want to run my 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.