综述
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++编译的脚本。
编译过程
X86平台编译
看了 sunny_老王 的 文章,在 Makefile.vc 编译脚本的开头部分插入”PLATFORM = X86″,如下图所示。
打开Visual Studio 2022的”x86 Native Tools Command Prompt for VS2022″窗口:
进入进入wincon目录,输入以下编译命令,编译 Debug 版本:
nmake -f Makefile.vc WIDE=Y UTF8=Y DLL=Y DEBUG=Y
不到一分钟编译完成:
这就是我们编译的成果:
先将这个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
同理,用以下命令编译 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)"
(5) C/C++ | Preprocessor | Preprocessor Definitions 新增:PDC_DLL_BUILD
(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();
}
执行结果:
参考文献
- PDCurses在Windows下编译流程https://blog.csdn.net/sinat_29235897/article/details/92850542
- How To Install ncurses Library on a Linux https://www.cyberciti.biz/faq/linux-install-ncurses-library-headers-on-debian-ubuntu-centos-fedora/
- Linux 下curses库 安装 和使用https://www.cnblogs.com/Chaobs/articles/4915335.html
- NCURSES Programming HOWTO https://tldp.org/HOWTO/html_single/NCURSES-Programming-HOWTO/
- PDCurses User’s Guide https://pdcurses.org/docs/USERS.html
- PDCurses for Windows console https://pdcurses.org/wincon/
- Windows终端屏幕显示库Public Domain Curses(PDCurses)使用https://www.cnblogs.com/dalanjing/p/8379705.html
- PDCureses 库的安装和使用https://piggerzzm.github.io/2019/07/28/PDCurses/
- An Introduction to ncurses in C https://medium.com/programming-in-c/an-introduction-to-ncurses-in-c-d977efd706f8
- PDCursesMod: Public Domain Curses modified/extended https://www.projectpluto.com/win32a.htm
- Game Programming in C with the Ncurses Library https://www.viget.com/articles/game-programming-in-c-with-the-ncurses-library/
- Writing Programs with NCURSES https://invisible-island.net/ncurses/ncurses-intro.html
- Ncurses学习经历(一) Ncurses简介与下载安装
- Ncurses学习经历(二) 编译包含ncurses库函数的程序
- Ncurses学习经历(三)窗口机制简介
- Ncurses学习经历(四) 输出修饰(对输出数据的修饰,加粗、下划线等)
- Ncurses学习经历(五)窗口机制详述
- Ncurses学习经历(六)颜色系统讲述
- Ncurses学习经历(七) 键盘管理
- Ncurses学习经历(八) 使用鼠标操作
- Ncurses学习经历(九)屏幕操作
- Ncurses学习经历(十)面板库详解
- Ncurses学习经历(十一)面板库——用户指针
- Ncurses学习经历(十二)菜单库
- Ncurses学习经历(十三)菜单系统的核心
(完)
Original: https://www.cnblogs.com/yapingxin/p/15936414.html
Author: 辛亚平
Title: 在Windows平台用Visual C++ 2022 (v143)编译PDCurses
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585482/
转载文章受原作者版权保护。转载请注明原作者出处!