在Windows平台用Visual C++ 2022 (v143)编译PDCurses

综述

PDCurses是一个开源的跨平台curses库,它提供了一组函数,开发者可以用这组函数在终端(Console、Terminal)上设置光标的位置和字符的显示样式。本文介绍在Windows平台(Windows 10)上用Visual Studio 2022版本的Visual C++编译PDCurses的过程。

获取PDCurses源代码

PDCurses的相关资源如下:

  • 官方网站:https://pdcurses.org/
  • Github代码仓库页面:https://github.com/wmcbrine/PDCurses
  • Git代码仓库地址:https://github.com/wmcbrine/PDCurses.git
  • SourceForge页面:https://sourceforge.net/projects/pdcurses
  • 文档:https://pdcurses.org/docs/

当前最新稳定版为3.9版(2019年9月5日发布)。下载名称为 3.9 的Tag压缩文件并解压,即可得到3.9版的PDCurses源代码。进入wincon目录,Makefile.vc 即用于Visual C++编译的脚本。

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

编译过程

X86平台编译

看了 sunny_老王文章,在 Makefile.vc 编译脚本的开头部分插入”PLATFORM = X86″,如下图所示。

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

打开Visual Studio 2022的”x86 Native Tools Command Prompt for VS2022″窗口:

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

进入进入wincon目录,输入以下编译命令,编译 Debug 版本:

nmake -f Makefile.vc WIDE=Y UTF8=Y DLL=Y DEBUG=Y

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

不到一分钟编译完成:

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

这就是我们编译的成果:

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

先将这个PDCurses-3.9文件夹重命名备份,再解压出一个新的PDCurses-3.9文件夹来。同理,用以下命令编译 Release 版本:

bash;gutter:false; nmake -f Makefile.vc WIDE=Y UTF8=Y DLL=Y</p> <pre><code> 编译成功: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225163901644-1285389733.png) 编译成果如下: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225164011425-374771973.png) ## X64平台编译 在 Makefile.vc 编译脚本的开头部分插入"PLATFORM = X64",如下图所示。 ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225164604946-527821727.png) 打开Visual Studio 2022的"x64 Native Tools Command Prompt for VS2022"窗口,用以下命令编译 Debug 版本: ;gutter:false;
nmake -f Makefile.vc WIDE=Y UTF8=Y DLL=Y DEBUG=Y

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

同理,用以下命令编译 Release 版本:

bash;gutter:false; nmake -f Makefile.vc WIDE=Y UTF8=Y DLL=Y</p> <pre><code> 执行结果: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225165306298-280032475.png) ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225165344964-1753846586.png) 应用示例 ## 设置环境变量 为了便于在程序中调用PDCurses,首先,将刚刚编译好的PDCurses库文件与头文件归置到适当的目录中: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225174204779-1756724766.png) 至于里面的文件怎么放置,当然是看 Visual C++ 的项目设置怎么方便怎么来。然后,设置系统环境变量PDCurses如下所示: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225174604041-1934333889.png) 检查一下系统是否已经能够正确识别该环境变量: ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225175135908-1497788853.png) ## 编程实例 在 Visual Studio 2022 中建立C/C++控制台应用程序项目,项目属性中: (1) C/C++ | General | Additional Include Directories 新增条目:$(PDCurses)\include ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225180207949-395191783.png) (2) Linker | General | Additional Library Directories 新增条目:$(PDCurses)\LIB\$(Platform)\$(Configuration) ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225200142277-182766578.png) (3) Linker | Input | Additional Dependencies 新增:pdcurses.lib ![在Windows平台用Visual C++ 2022 (v143)编译PDCurses](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/2284104-20220225200341622-370490950.png) (4) Build Events | Post-Build Event | Command Line 新增: ;gutter:false;
copy "$(PDCurses)\DLL\$(Platform)\$(Configuration)\pdcurses.dll" "$(TargetDir)"

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

(5) C/C++ | Preprocessor | Preprocessor Definitions 新增:PDC_DLL_BUILD

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

(6) 编写代码:

cpp;gutter:true;</p> <h1>include</h1> <h1>include</h1> <h1>include "Curses/curses.h"</h1> <p>void initialize(); void shutdown();</p> <p>int main() { char ch = '\n'; char* message = "Hello, World!";</p> <pre><code>initialize(); do { mvprintw(LINES / 2, (COLS - (int)strlen(message)) / 2, message); refresh(); ch = getch(stdscr); } while (ch != 'Q' && ch != 'q'); shutdown(); return 0; </code></pre> <p>}</p> <p>void initialize() { initscr(); start_color(); raw(); cbreak(); noecho(); curs_set(0); srand((unsigned int)time(NULL)); }</p> <p>void shutdown() { endwin(); }

执行结果:

在Windows平台用Visual C++ 2022 (v143)编译PDCurses

参考文献

(完)

Original: https://www.cnblogs.com/yapingxin/p/15936414.html
Author: 辛亚平
Title: 在Windows平台用Visual C++ 2022 (v143)编译PDCurses

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585482/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球