Curses library not found
For some reason, CMake can't find includes and libraries. Help it by running cmake -D CMAKE_PREFIX_PATH=/path/to/curses/prefix .
How to link curses.h in Cmake?
Basically the same way you locate and integrate about any third-party library with CMake: Using one of the packaged Find___.cmake
modules.
These are located in share/cmake-X.Y/Modules
of your CMake installation directory. Check the files themselves for their individual documentation, and cmake --help-command find_package
for details on how to call them.
I haven't tried the following with PDCurses on MinGW specifically, but if it doesn't work, that'd a clear bug report to Kitware (the makers of CMake):
find_package( Curses REQUIRED )
include_directories( ${CURSES_INCLUDE_DIRS} )
target_link_libraries( Project1 ${CURSES_LIBRARIES} )
The following variables are set as appropriate to tell you which header is available:
CURSES_HAVE_CURSES_H
forcurses.h
CURSES_HAVE_NCURSES_H
forncurses.h
CURSES_HAVE_NCURSES_NCURSES_H
forncurses/ncurses.h
CURSES_HAVE_NCURSES_CURSES_H
forncurses/curses.h
Additional advice:
file(GLOB Project1_SRC
"*.h"
"*.c"
)
Don't do that.
To quote from the documentation of that very function:
We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
Don't do that either.
You do not want any generated files to end up in your source directory (where they get in the way of your versioning system, or worse, get actually checked in to the repository). You want to generate everything in the binary directory, cleanly out of the way.
Right way to tell CMake to find (n)curses in non-default location?
You can provide additional search paths through CMAKE_PREFIX_PATH
.
Paths within CMAKE_PREFIX_PATH
are searched first.
You can specify CMAKE_PREFIX_PATH
either hardcoded in the CMakeLists.txt file or, preferably, through:
cmake -D CMAKE_PREFIX_PATH=/path/where/brew/installed/curses .
Can't compile with CMake and ncurses
The solution is to add a line like this:
target_link_libraries(client ncurses)
This tells CMake that when it is linking the client
target, it should use the -lncurses
option to link in the ncurses library.
cmake does non link ncurses
For the super noob, remember target_link_libraries()
needs to be below add_executable()
:
cmake_minimum_required(VERSION 2.8) project(main)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_executable(main main.cpp)
target_link_libraries(main ${CURSES_LIBRARIES})
Related Topics
How to Delete Everything in a String After a Specific Character
How to Run Linux Docker Images on Windows Server 2016
Getting Exit Status Code from 'Ftp' Command in Linux Shell
Elf Program Header Virtual Address and File Offset
"Cd" Does Not Work in Shell Script
How to Pass All Arguments with Xargs in Middle of Command in Linux
Source Code of Pthread Library
Get the Characters After the Last Index of a Substring from a String
Check If File Is Open with Lsof
Determine If Relative or Absolute Path in Shell Program
Delete Whitespace in Each Begin of Line of File, Using Bash
Ubuntu Equivalent of Yum's Whatprovides, to Find Which Package Provides a File
Can't Build 32Bit Wine on 64Bit Linux
Lowest Latency Notification Method Between Process Under Linux
Bash Script to Get All Ip Addresses
How to List the Files in a Zip Archive Without Decompressing It