在 Linux 和 Windows 中启用诅咒
Enabling curses in both Linux and Windows
我正在C++从事小项目,我正在使用curses作为用户界面。我能够很好地让它在我的 arch-linux 安装中工作,因为设置 ncurses 在那里工作非常简单。但是我的 cmake 设置在 Linux 上运行良好,我无法使其在 Windows 上正常工作。
这是我的CMakeList.txt
cmake_minimum_required(VERSION 3.9)
project(fighting_pit)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 11)
include_directories( ./include)
include_directories( ./src)
add_executable(fighting_pit
include/Arena.h
include/cursor.h
include/Player.h
include/spell.h
include/Turns.h
include/weapon.h
include/Draw.h
src/Arena.cpp
src/cursor.cpp
src/Player.cpp
src/spell.cpp
src/Turns.cpp
src/weapon.cpp
src/Draw.cpp
main.cpp )
target_link_libraries(fighting_pit ${CURSES_LIBRARIES})
我也尝试了几种方法使其在Windows上运行。
1. 下载源码
我试图用mingw32-make构建pdcurses。它创建了 pdcurses.a 我将其添加到与项目相同的位置,但它仍然显示它找不到诅咒库。
2. 通过 mingw32-get 下载
我使用了 mingw 的安装管理器,让它下载 libpdcurses 的 .dll 和开发包。只是试图通过 clion 运行 cmake 表明它仍然没有找到。所以我把它都复制到 windows32 和项目文件夹中,但它仍然没有帮助。
我不知道我应该怎么做。 不幸的是,我既不是C++用户也不是Windows用户。
我需要构建一个跨平台的项目,在Linux和MacOS上使用ncurses,但在Windows上使用pdcurses。curses 的某些变体通常安装在流行的 Linux 发行版上。ncurses 在 MacOS 上也可用。对于Windows来说,情况并非如此。我的解决方案是下载 pdcurses 源代码并编写一个 cmake 脚本以在 Windows 上构建它。if (WIN32 or MSVC)
构建 pdcurseselse()
找到 ncurses。您可能还希望创建一个代理标头,该标头根据平台#include
的 pdcurses 或 ncurses。
克隆 GitHub 存储库后,我将.
中的标头、./pdcurses
中的 C 文件、./wincon
中的源代码复制到项目中的新目录中。然后我编写了一个CMakeLists.txt
文件,将所有这些文件编译到一个库中。它看起来像这样:
cmake_minimum_required(VERSION 3.2)
add_library(PDcurses
# all of the sources
addch.c
addchstr.c
addstr.c
attr.c
beep.c
# ...
)
target_include_directories(PDcurses
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
如果目标是 windows,我的主要CMakeLists.txt
文件编译了 pdcurses 源代码。
if(WIN32 OR MSVC)
add_subdirectory(pdcurses)
target_link_libraries(MyTarget
PRIVATE
PDcurses
)
else()
# find ncurses and use that
endif()
在大多数情况下,PDCurses 似乎是 ncurses 的(或多或少(替代品。我能够使用curses在我的Mac上编译PDcurses附带的示例程序,没有任何麻烦。
- 编译时未启用intel oneApi CUDA支持
- OpenGL在启用深度测试时不会丢弃我的碎片
- Visual C++GC接口如何启用它以及要包含哪个库
- 如何在自定义类中启用'auto loops'?
- 根据某个函数是否存在启用模板
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 启用从"vector<const T>&"到"const vector&"的隐式转换<T>
- C++ win32 如何使密码字段可选并启用复制和粘贴?
- 在 Eclipse 上启用 C++17 以使用 'std::byte'
- 当 noexcept 函数尝试在 gcc 或 clang 中调用非 noexcept 函数时启用警告
- 如何为一段代码启用 -permissive
- 是否可以/希望创建不可复制的共享指针模拟(以启用weak_ptr跟踪/借用类型语义)?
- 在 GCC 中启用"differing levels of indirection"警告/错误
- 使用 Doxygen 记录枚举类值,而不启用EXTRACT_ALL
- '_HAS_CXX17'宏是否可用于自定义项目标头以启用C++17 语言集功能?
- 如何与诅咒划清界限?
- 如何启用转换模板参数 T 以常量 T?
- 在使用 gSoap 链接多个 SOAP 服务时启用保持活动状态
- 如何启用标准::实验::atomic_shared_pointer
- 在 Linux 和 Windows 中启用诅咒