1

I've been at this problem for a while now and couldn't find anything to solve my problem. I'm trying to use the ncurses.h library in my program but the linker failed and told me that I had undefined symbols. I fixed that by creating a new folder called includes and copying the location of ncurses.h from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ncurses.h to the new folder. Then I put this line into my CMakeLists.txt file: target_link_libraries(<project name> includes/ncurses.h). But then I got another error saying ld: library not found for -lincludes/ncurses.h. I've tried using add_library() but that gave me an error saying:

The target name "includes/ncurses.h" is reserved or not valid for certain
  CMake features, such as generator expressions, and may result in undefined
  behavior.

Does anyone have any other suggestions?

Matthew Schell
  • 599
  • 1
  • 6
  • 19

1 Answers1

1

To find the location of the ncurses library, you will need to use the find_package() to locate the Curses package. The find_package() will return the CURSES_INCLUDE_DIR and CURSES_LIBRARY environment variables with the location of the include files and library.

Following is minimal example that works in CLion on macOS with:

CMakeLists.txt

cmake_minimum_required(VERSION 2.9)
project(test)

find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})

add_executable(test test.c)
target_link_libraries(test ${CURSES_LIBRARY})

test.c

#include <ncurses.h>

int main()
{
    initscr();          /* Start curses mode          */
    printw("Hello World !!!");  /* Print Hello World          */
    refresh();          /* Print it on to the real screen */
    getch();            /* Wait for user input */
    endwin();           /* End curses mode        */

    return 0;
}
jordanvrtanoski
  • 5,104
  • 1
  • 20
  • 29