在CLion CMake中链接ncurses

Jos*_*ker 6 c++ ncurses

我正在玩ncurses.Ncurses是我安装的库,不是我自己的文件.我已经做了一些事情,但使用IDE更容易,所以我决定使用CLion(我在Linux上,所以不能使用Visual Studio).我得到了以下CMakeLists.txt:

cmake_minimum_required(VERSION 3.6)
project(ncurses)

set(CMAKE_C_STANDARD "${CMAKE_C_FLAGS} -Wall -Werror -lpdcurses")

set(SOURCE_FILES main.cpp ncurses.h)
add_executable(ncurses ${SOURCE_FILES})
Run Code Online (Sandbox Code Playgroud)

我的项目被称为ncurses我不知道这是否重要.

我得到了以下main.cpp

#include <ncurses.h>

int main() {
    initscr();
    printw("Hello");
    refresh();
    getch();
    endwin();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

/opt/clion/bin/cmake/bin/cmake --build /home/josh/ClionProjects/ncurses /cmake-build-debug --target all -- -j 4
make[2]: *** No rule to make target 'CMakeFiles/ncurses.dir/build'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/ncurses.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Run Code Online (Sandbox Code Playgroud)

我不知道问题是什么.我尝试过-lncurses,lpdcurses但是这也不起作用.它只会在构建时出错,但在IDEA本身时不会出错.

Vel*_*lse 4

在你的CMakeLists.txt

只需添加:

set(CMAKE_CXX_FLAGS "-lncurses")
Run Code Online (Sandbox Code Playgroud)