简体   繁体   English

如何在 Windows 中安装 PDCurses 以与 C++ 一起使用?

[英]How do I install PDCurses in Windows for use with C++?

I want to use it in some of my programs instead of the standard IOStream.我想在我的一些程序中使用它而不是标准的 IOStream。

Also, does NCurses work on Windows, and if so, any better?另外,NCurses 是否在 Windows 上工作,如果是这样,更好吗?

Download the zip file , unpack it wherever you typically put external libraries, and check the readme, which tells you the following:下载 zip 文件,将其解压缩到通常放置外部库的任何位置,然后检查自述文件,其中会告诉您以下内容:

PDCurses has been ported to DOS, OS/2, Win32, X11 and SDL. PDCurses 已被移植到 DOS、OS/2、Win32、X11 和 SDL。 A directory containing the port-specific source files exists for each of these platforms.每个平台都有一个包含特定于端口的源文件的目录。 Build instructions are in the README file for each platform.构建说明位于每个平台的 README 文件中。

The readme file in the Win32 directory tells you that there are makefiles for several different compilers. Win32 目录中的自述文件告诉您有几个不同编译器的生成文件。 In short, you run make :简而言之,你运行make

make -f makefilename

It tells mentions a couple of options you can set, including WIDE and UTF8.它提到了您可以设置的几个选项,包括 WIDE 和 UTF8。

To then use the library, add the directory that contains curses.h to your include path and link with the pdcurses.lib file that make generates for you.使用该库,请将包含curses.h的目录添加到您的包含路径并链接到make为您生成的pdcurses.lib文件。 How you modify your include path and your linked libraries depends on your development environment and is largely irrelevant to PDCurses.如何修改包含路径和链接库取决于您的开发环境,并且在很大程度上与 PDCurses 无关。

I finally made it.我终于做到了。 First Build/Compile the Source according to docs.首先根据文档构建/编译源代码。

make -f Makefile # did for me, Windows 10

Copy curses.h and panel.h into your include folder.curses.hpanel.h复制到include文件夹中。 And, Copy wincon/pdcurses.a into your lib folder.并且,将wincon/pdcurses.a复制到您的lib文件夹中。 Rename pdcurses.a to libpdcurses.a .pdcurses.a重命名为libpdcurses.a (Because it's the standard). (因为这是标准)。

Now, You can include curses.h and compile it like this.现在,您可以包含curses.h并像这样编译它。

g++ main.cpp -lpdcurses

On VSCode在 VSCode 上

[Step 1] Install MinGW : [步骤 1] 安装 MinGW:

  • MinGW installation steps MinGW安装步骤
  • ^(make sure you followed the steps carefully) ^(请确保您仔细按照步骤操作)

[Step 2] BUILD PDCurses: [步骤 2] 构建 PDCurses:

  • Download PDCurses-master.zip and extract the content下载PDCurses-master.zip并解压内容

  • Run MSYS2 MinGW 64-bit (or MSYS2 MinGW 32-bit ^1 )运行MSYS2 MinGW 64-bit (或MSYS2 MinGW 32-bit ^1

  • cd into the wincon folder and run make -f Makefile WIDE=Y DLL=Y source cd进入wincon文件夹并运行make -f Makefile WIDE=Y DLL=Y source

[Step 3] Copy Files: [步骤 3] 复制文件:

If you followed the steps above so far correctly, there should be 2 specific files inside wincon folder called pdcurses.a and pdcurses.dll如果您正确地遵循了上述步骤,则wincon文件夹中应该有 2 个特定文件,名为pdcurses.apdcurses.dll

  • rename pdcurses.a to libpdcurses.apdcurses.a重命名为libpdcurses.a
  • copy pdcurses.dll into C:\\msys64\\mingw64\\binpdcurses.dll复制到C:\\msys64\\mingw64\\bin
  • copy libpdcurses.a into C:\\msys64\\mingw64\\liblibpdcurses.a复制到C:\\msys64\\mingw64\\lib
  • copy curses.h and panel.h form PDCurses-master folder into C:\\msys64\\mingw64\\includecurses.hpanel.hPDCurses-master文件夹复制到C:\\msys64\\mingw64\\include

[Step 4] Build an example: [步骤 4] 构建示例:

  • Install the C/C++ extension安装C/C++ 扩展

  • Follow those steps to create a working enviroment inside VSCode按照这些 步骤在 VSCode 中创建一个工作环境

  • Add "-lpdcurses" under "args": into tasks.json"args":下添加"-lpdcurses" "args":tasks.json

  • and you are Done (at least those steps worked for me)你已经完成了(至少这些步骤对我有用)

Extra额外的

  • ^1 if you want to build for 32 systems a good rule is to follow all steps above but wherever you see 64 replace it with 32 ^1如果你想为 32 个系统构建一个好的规则是按照上面的所有步骤但是你看到 64 的地方用 32 替换它
  • you can also just manually build an example by runing g++ your_example.c -o your_example -lpdcurses inside MSYS2 MinGW 64-bit terminal if you want so [...]如果需要,您也可以通过在MSYS2 MinGW 64-bit终端中运行g++ your_example.c -o your_example -lpdcurses手动构建示例 [...]
  • demos / examples演示/示例

how things should look like:事情应该是什么样子:

在此处输入图片说明

  • c_cpp_properties.json c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win64",
            "includePath": [
                "${default}"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}
  • launch.json启动文件
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}
  • tasks.json:任务.json:
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-lpdcurses"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM