2016-12-07 230 views
4

我目前正在玩弄ncurses。 Ncurses是我安裝的庫,不是我自己的文件。我已經做了一些東西,但使用IDE更容易,所以我決定使用CLion(我在Linux上,所以不能使用Visual Studio)。我得到了以下的CMakeLists.txt:CLion CMake鏈接ncurses

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}) 

我的項目被稱爲ncurses的,我不知道這是否會事。

我得到了下面的main.cpp

#include <ncurses.h> 

int main() { 
    initscr(); 
    printw("Hello"); 
    refresh(); 
    getch(); 
    endwin(); 
    return 0; 
} 

不過,我得到以下錯誤:

/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 

我不明白是什麼問題。我試過-lncurses,但lpdcurses除外,但也不起作用。它只在構建時發生錯誤,而不在IDEA中發生。

回答

0

CMakeLists.txt

只需添加:

set(CMAKE_CXX_FLAGS "-lncurses")