0

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

  • 1
    Well, you'll need to compile the complete curses package into libraries (`libncurses`, `libforms`, etc ...) that you can link with. It can be done, but unless you need the very latest development release of ncurses, I'd go for installing a ready-made package. – Ted Lyngmo Feb 20 '20 at 17:27
  • Actually this program that I wrote needs to be run on university machines and ncurses isn't supported in those machines, so I need to do it in this way –  Feb 20 '20 at 17:30
  • Ok, you do not need the header files for running your program, so forget about those. If the university machines have a termcap database, I bet ncurses is supported. Is your program compiled on a compatible machine? Have you linked with the curses libraries statically? (see @Jabberwocky's link below) – Ted Lyngmo Feb 20 '20 at 17:32
  • 1
    https://stackoverflow.com/questions/3514852/statically-link-ncurses-to-program ? – Jabberwocky Feb 20 '20 at 17:33
  • @TedLyngmo for now I have used the library installed in my computer and I don't link staticly –  Feb 20 '20 at 17:36
  • Ok, then try linking statically. Have you been able to compile your programs at home and run them at the uni computers before so you know they are compatible? What errors do you get when you try to execute your `ncurses` program at the uni computer? – Ted Lyngmo Feb 20 '20 at 17:38
  • @TedLyngmo No I hav'nt try that. But there is something else that I should tell. I downloaded ncurses source code from github repo but I don't know how to link it to my code. Because what I downloaded from github repo is a very huge folder with lots of subdirectories and a lot of files –  Feb 20 '20 at 17:40
  • I bet it is huge. What operating system do you have at home and what are they running on the uni computers? – Ted Lyngmo Feb 20 '20 at 17:42
  • @TedLyngmo I have linux Manjaro at home and linux ubuntu at uni –  Feb 20 '20 at 17:43
  • Download and compile ncurses, but when you do `./configure`, make it `./configure --prefix=/home/yourname/ncurses` or something. (Not sure if --prefix is the right setting) – user253751 Feb 20 '20 at 17:47
  • @user253751 `./configure --prefix /home/yourname/ncurses` would be it. I just did it :-) – Ted Lyngmo Feb 20 '20 at 17:49
  • @TedLyngmo make that an answer. – user253751 Feb 20 '20 at 17:50
  • @user253751 I'll go through all the hoops first so I don't lie. – Ted Lyngmo Feb 20 '20 at 17:51
  • @user253751 after downliding it, how could I compile it? Or I do directely ./configure? I am confused –  Feb 20 '20 at 18:04
  • @Mohammadreza I made a step-by-step instruction of what I just did. Hope it works for you too. – Ted Lyngmo Feb 20 '20 at 18:59

1 Answers1

3

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 (*)

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • thank you so much for your answer and the time that you put into this ... I tested on my omputer and everything works ... I just have to test it in uni ... just one small question : Do I have to do `#include ` or `#include ""local/include/ncursestw/curses.h"`? because I did both and it worked but the thing is that I have ncurses already installed in my machine. –  Feb 20 '20 at 21:33
  • 1
    Glad it helped! The flags `-I ~/local/include -I ~/local/include/ncursestw` are there so the compiler will look for `curses.h` in those directories too, so `` is enough. – Ted Lyngmo Feb 20 '20 at 21:37
  • One caveat: You may have to redo this procedure on the uni computer. One program compiled for one platform often won't run on another, so bring your source code, download ncurses and recompile everything there too. – Ted Lyngmo Feb 20 '20 at 22:54