0

I'm trying to compile a short test program for my raspberry pi in CLion. I've set up two toolchains, one that compiles with gcc and g++ so I can test the program locally, and one that compiles with the raspberry pi cross compiler using arm-linux-gnueabihf-gcc and arm-linux-gnueabihf-c++ (from the official raspberry pi cross compiler).

When I compile with my local toolchain, no errors occur and it works as expected. When I switch to the raspberry pi toolchain, I get this error:

/home/[username]/CLionProjects/untitled/main.cpp:1:10: fatal error: ncurses.h: No such file or directory

I thought this may be an issue with my CmakeLists.txt file, but it compiles without any issues with the local toolchain. Both toolchains work without ncurses, I tested them with a simple hello world program using std::cout rather than ncurses, and they compiled and ran on their respective devices.

    cmake_minimum_required(VERSION 3.13)
    project(untitled)
    set(CMAKE_CXX_STANDARD 14)
    set(CURSES_USE_NCURSES TRUE)
    find_package(Curses REQUIRED)
    include_directories(${CURSES_INCLUDE_DIR})
    set(CMAKE_CXX_FLAGS "-lncurses")
    set(CMAKE_C_STANDARD "%{CMAKE_C_FLAGS} -Wall -Werror -lpdcurses")
    set(SOURCE_FILES main.cpp)
    add_executable(untitled ${SOURCE_FILES})
    target_link_libraries(untitled ncurses)

I've also included the following lines in my FindCurses.cmake file per this question

    set(CMAKE_INCLUDE_PATH "/usr/include/ncurses.h")
    set(CMAKE_LIBRARY_PATH "/lib/x86_64-linux-gnu/libncurses.so")

I'm not sure what I'm doing wrong here and would appreciate any and all help.

socks
  • 1
  • 1
  • What is content of `CURSES_INCLUDE_DIR` variable? You use that variable in `include_directories` statement. (You may print the variable's value with `message` command). Note, that [documentation](https://cmake.org/cmake/help/v3.7/module/FindCurses.html) for `FindCurses` module suggests to use `CURSES_INCLUDE_DIRS` instead of `CURSES_INCLUDE_DIR`. Also, `set(CMAKE_CXX_FLAGS "-lncurses")` is wrong: `-l` is a **linker** flag, not a *compiler* one for which `CMAKE_CXX_FLAGS` variable is intended. And you setting `set(CMAKE_C_STANDARD ...` is just a trash... – Tsyvarev Nov 26 '19 at 20:05
  • Did you compile and install ncurses library crosscompiled for the target architecture and installed in the crosscompiler library search paths? – KamilCuk Nov 26 '19 at 20:05
  • both CURSES_INCLUDE_DIR and CURSES_INCLUDE_DIRS message back /usr/include, the folder that contains ncurses.h. the -lncurses flag was recommended by several other SO questions about getting ncurses to work properly, so I included it and it solved an earlier issue. the cmake standard line was automatically added by my IDE. – socks Nov 26 '19 at 20:55
  • Welcome to Stackoverflow! I agree the `set(CMAKE_C_STANDARD ...` command looks peculiar. Note that `CMAKE_INCLUDE_PATH` and [`CMAKE_LIBRARY_PATH `](https://cmake.org/cmake/help/latest/variable/CMAKE_LIBRARY_PATH.html) should be **paths**, not files. – Kevin Nov 26 '19 at 21:19
  • Okay, I changed the `CMAKE_LIBRARY_PATH` and `CMAKE_INCLUDE_PATH` into paths and not files, no changes. I removed the `set(CMAKE_C_STANDARD ...` line with no changes as well. I have also downloaded the ncurses files from my raspberry pi and tried to get them to work with the help of [this](https://stackoverflow.com/questions/19162072/how-to-install-the-raspberry-pi-cross-compiler-on-my-linux-host-machine) post, as well as changing `CMAKE_LIBRARY_PATH` and `CMAKE_INCLUDE_PATH` to point to the cross-compiled libraries to no avail. – socks Nov 27 '19 at 00:09

0 Answers0