vcmkrtchyan
vcmkrtchyan

Reputation: 2626

LInk Curses in Mac OS CMake

I want to make my CLion compatible with curses library for C. Here's my sample application

#include <stdio.h>
#include "ncurses.h"

int main() {
    initscr();
    printw("Hello world");
    refresh();

    getch();
    endwin();
    return 0;
} 

And here's my CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(untitled C)

set(CMAKE_C_STANDARD 99)

add_executable(untitled main.c)
target_link_libraries(${PROJECT_NAME} ncurses)

But when I run the application, I get into this error

Error opening terminal: unknown.

Upvotes: 1

Views: 521

Answers (1)

Heider Sati
Heider Sati

Reputation: 2614

you need to edit your CMakeLists.txt file to be as follows:

cmake_minimum_required(VERSION 3.17)
project(untitled C)

set(CMAKE_CXX_STANDARD 14)

add_compile_options(-g -Wall -Wextra -pedantic)

set(INCLUDE_DIR include)
include_directories (${INCLUDE_DIR})

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

add_executable(untitled main.cpp)

target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES})

Just tested it now, and it works fine in Clion latest version ( mine at the time of writing this answer is v2020.3)

Mind you, it's not possible to debug the lib commands, but you can compile and run in the console-terminal (i.e. don't run it from the "terminal" that is inside CLion, use the system one instead), this is because the code is designed to run in a text-type terminal whilst the one inside of CLion is a Graphical one.

I hope this helps

Good luck,

H

Upvotes: 1

Related Questions