DEV Community

Cover image for Import <ncurses.h> library in C on Mac
Vinay Patil
Vinay Patil

Posted on

2

Import <ncurses.h> library in C on Mac

If you’re coding in C (which I highly doubt, but if you are!) and you see many people importing <ncurses.h> while encountering errors in your ncurses library functions—even after installing ncurses—this guide might solve your issue.


1.first step is to install ncurses, if you already did skip this step.

brew install ncurses
Enter fullscreen mode Exit fullscreen mode

2.locate where the library is installed

brew info ncurses
Enter fullscreen mode Exit fullscreen mode

3.The output will include where the library is installed something like:

/opt/homebrew/Cellar/ncurses/6.5
Enter fullscreen mode Exit fullscreen mode

remember your version like mine is 6.5

4.Verify for the libraries and headers:

ls /opt/homebrew/Cellar/ncurses/6.5/lib
ls /opt/homebrew/Cellar/ncurses/6.5/include
Enter fullscreen mode Exit fullscreen mode

remember to change your version

  1. Add ncurses to Your Compile Path
gcc main.c -o main -I/opt/homebrew/Cellar/ncurses/6.5/include -L/opt/homebrew/Cellar/ncurses/6.5/lib -lncurses
Enter fullscreen mode Exit fullscreen mode

replace version

  1. Update Environment Variables
export CPPFLAGS="-I/opt/homebrew/Cellar/ncurses/6.5/include"

export LDFLAGS="-L/opt/homebrew/Cellar/ncurses/6.5/lib"
Enter fullscreen mode Exit fullscreen mode

replace version number

7.Now you can compile your file using :

gcc main.c -o main -lncurses
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay