user12340167
user12340167

Reputation:

using ncurses without installing it

I am working on a project which uses ncurses. I am wondering if there is a way to use this library without installing it on a machine? What I mean is that instead of installing it, is there a way to have .h files and compile them in a makefile and use them?
Thank you in advanced for your response

Upvotes: 0

Views: 1818

Answers (1)

Ted Lyngmo
Ted Lyngmo

Reputation: 117258

It seems like you need to build it yourself, so here's how it can be done:

  • Create a directory where you do local installations of external packages that you download, build and install. They often default to /usr/local, but I assume you don't have admin rights, so you can create a local in your home directory instead.
    cd ~
    mkdir local
    
  • If you haven't before, you may create a directory for repositories that you download:
    mkdir ~/repos
    cd ~/repos
    
  • Clone ncurses
    git clone https://github.com/mirror/ncurses.git
    cd ncurses
    
  • Configure ncurses
    This configures it to be installed in your newly created local directory, with wide character (UTF-8) and threading support. You can experiment with other options (but note that it'll effect the naming of the directories and libraries). It also configures ncurses to create static libraries (it's the default).
    ./configure --prefix ~/local --enable-widec --with-pthread
    
  • Build and install:

    make -j
    make -j install
    

    Your ~/local directory should now look like this:

    bin  include  lib  share
    
  • When compiling your own programs, add
    -I ~/local/include -I ~/local/include/ncursestw -L ~/local/lib
    to the command line. Note the t (for threads) and w (for wide) on the directory.

    When linking, you need to link with ncursestw, dl and pthread.

    Example:

    g++ -I ~/local/include -I ~/local/include/ncursestw -L ~/local/lib \ 
                           -o prog prog.cpp -lncursestw -ldl -pthread
    

    Note that linking with the pthread library is best done with -pthread not -lpthread (*)

Upvotes: 3

Related Questions