4

I'm building a school project application which requires the use of ncurses library. While trying to use mvwaddwstr() function, I get the following error: undefined reference to `mvwaddwstr'.

My CMake configuration file is as follows:

cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_STANDARD 11)

project(client)

# Libraries
find_package(Curses REQUIRED)
find_package(Threads REQUIRED)
include_directories(${CURSES_INCLUDE_DIRS})

# Sources
set(CLIENT_SOURCE_FILES
        main.c)

# Links
add_library(client_library ${CLIENT_SOURCE_FILES})
add_executable(client ${CLIENT_SOURCE_FILES})
target_link_libraries(client ${CURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(client INTERFACE
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")

Edit

As suggested I tried adding:

set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)

include(FindCurses)

before the find_package line but it still ain't working.

EpaXapate
  • 171
  • 10
  • See [source](https://github.com/Kitware/CMake/blob/master/Modules/FindCurses.cmake#L49), which shows you have to set `CURSES_NEED_WIDE`. – Thomas Dickey Jan 14 '18 at 17:27
  • @ThomasDickey checked it out, added the required variables and included the ``FindCurses`` module, still nothing – EpaXapate Jan 14 '18 at 17:34
  • i deleted the answer because in newer cmake versions this is completely different ... see https://stackoverflow.com/questions/29901352/appending-to-cmake-c-flags/29901579 – ralf htp Jan 14 '18 at 20:10
  • You create **two targets** - an executable and a library, but links only one of them. For which target do you get "undefined reference" error? – Tsyvarev Jan 14 '18 at 21:33
  • @Tsyvarev to the executable – EpaXapate Jan 14 '18 at 23:58
  • 2
    Then remove `client_library` from the tested code, as it is unrelated to the problem. Also, `target_include_directories(INTERFACE)` is *useless* for executable targets - you cannot link with it anyway. Make sure that after appending curses-related switches before `find_package()` you have made **clean reconfigure** (that is, the build directory has been emptied or, at least, `CMakeCache.txt` file is removed from it). Call `include(FindCurses)` noted in "Edit" section is **wrong** - `Find*` scripts are always used via `find_package()`. – Tsyvarev Jan 15 '18 at 07:30
  • After `find_package(Curses)` call add line `message(STATUS "CURSES_LIBRARIES: ${CURSES_LIBRARIES}")` - it will show actual result of `find_package()` call which you use for linking. – Tsyvarev Jan 15 '18 at 07:35
  • Which version of Curses library are You using? CMake version? Also, are You flushing Your build directory between experiments? – Kamiccolo Jan 16 '18 at 15:07
  • @Kamiccolo I have installed the latest Curses library version; CMake version is 3.9.6; finally yes I tend to clean the built folder quite a lot of times – EpaXapate Jan 17 '18 at 15:58
  • @EpaXapate please, be more precise. "Latest" from repositories? Latest from upstream? So You've built it from source? What distro? – Kamiccolo Jan 18 '18 at 11:41
  • @Kamiccolo I don't know the exact version number as I'm unable to verify that at the moment, but it was downloaded from the apt-get repository using xUbuntu distro – EpaXapate Jan 18 '18 at 15:14
  • dpkg -l | grep curses? – Kamiccolo Jan 18 '18 at 15:41

0 Answers0