首页 > 解决方案 > 带有 Visual Studio Code 的 FLTK 库

问题描述

我正在尝试从编程原理和实践中安装第 12 章的 FLTK 库,但无法识别构建命令。我应该怎么办?谢谢!

PS D:\3. Programming\C++\GUI\fltk-1.3.5> make
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path 
was included, verify that the path is correct and try again.
At line:1 char:1
+ make
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (make:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

标签: c++visual-studio-codefltk

解决方案


我通常对 Makefile 感觉更舒服,所以我设置了 VS Code 以在我的项目中使用 Makefile。我在安装 FLTK 后完成了以下步骤。

  1. 我创建了一个目录,其中包含我所有的源文件、头文件等。假设我有一个FLTK_ex文件夹hello.cpp及其Makefile

  2. 我打开 VS Code,然后File->Open选择文件夹FLTK_ex

  3. Terminal菜单中,我选择Configure Default Build Task...:在出现的菜单中,我选择Create tasks.json file from template然后Others

  4. 出现一个默认的json文件,我修改为

    {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build",
            "type": "shell",
            "command": "Make",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
    

    }

  5. 要编译,请转到Terminal菜单并选择Run Build Task...

  6. 要运行程序,请在Run菜单中选择Run without debugging,C++

  7. 出现一个launch.json文件:修改为(myprogram可执行文件名在哪里)

     {
    
     "version": "0.2.0",
     "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/myprogram",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
        ]
    }
    
  8. 为了有效地运行程序,在Run菜单中再次选择Run without debugging

我有 FLTK 1.3.5、macOS Catalina 10.15.5、clang 版本 11.0.3、VS Code 1.47。


为了在 VS Code 中使用 FLTK,我只是按照说明 (in Readme.OSX.txt) 来简单地安装 FLTK 库,Windows 系统有一个类似的文件 ( README.MSWindows.txt)。

编写MakefileforFLTK的指南在此处,如果您需要更多关于Makefiles 的见解,您可以在此处找到完整指南或此处找到更简短的介绍。



推荐阅读