FindCurses doesn't pull correct linker flags
When trying to link NCruses via CMake
A minimal example to reproduce on my system:
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(main)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_executable(main main.cpp)
target_link_libraries(main ${CURSES_LIBRARIES})
main.cpp
#include <ncurses.h>
int main() {
initscr(); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
[omtcyfz@omtcyfz-arch build]$ ninja -v
[1/1] : && /usr/bin/c++ CMakeFiles/main.dir/main.cpp.o -o main -lcurses -lform && :
FAILED: main
: && /usr/bin/c++ CMakeFiles/main.dir/main.cpp.o -o main -lcurses -lform && :
/usr/bin/ld: CMakeFiles/main.dir/main.cpp.o: undefined reference to symbol 'stdscr'
/usr/lib/libtinfo.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Affected NCurses version: 6.0+20170902-2 installed from Arch core packages. CMake version: 3.9.4-1.
I recently submitted a bug for Arch Linux ncurses package and the response was:
Most likely you'll need -ltinfo as well. Arch's ncurses is split into libncurses+libtino+libtic since 6.0+20170902-2
As far as my understanding goes, the "correct" way of handling it would be asking pkg-config, which is the default build system for NCurses, for the correct linker flags instead of hardcoding them.
Here's one more related discussion.
Edited by Kirill Bobyrev