带有Visual Studio Code的FLTK库

问题描述

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

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

解决方法

您尚未指定要使用的Visual Studio版本。

  1. 转到IDE目录,查找您的Visual Studio版本,然后查找fltk解决方案。在Visual Studio中启动解决方案。
  2. 默认情况下,每当您从发行版启动FLTK解决方案时,解决方案配置均为Debug Cairo。将此更改为Debug或Release
  3. 检查启动项目-应该是一个名为Demo的项目。
  4. 开始构建-它也应该构建所有测试可执行文件。
,

我通常对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 templateOthers

  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 debuggingC++

  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代码1.47。


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

Makefile编写FLTK的准则是here,如果您需要对Makefile的更多见解,可以找到完整的指南here或简短的介绍here


,
<p>This works for me.</p>
<p>Watch the library list. -X11 has to be before -lfltk</p>
<p>Not sure about the tabs,but leave them in.</p>
<h2>c_cpp_properties.json</h2>

<pre><code>
{
    "env": {
        "myDefaultIncludePath": [
            "${workspaceFolder}","${workspaceFolder}/include"
        ],"myCompilerPath": "/usr/bin/g++"
    },"configurations": [
        {
            "name": "include paths","intelliSenseMode": "linux-gcc-x64","includePath": [

                "/usr/include/cairo","/usr/include/glib-2.0","/usr/lib/x86_64-linux-gnu/glib-2.0/include","/usr/include/pixman-1","/usr/include/uuid","/usr/include/freetype2","/usr/include/libpng16","/usr/include/cairo","/usr/include/libpng16"

            ],"compilerPath": "/usr/bin/g++","cStandard": "c11","cppStandard": "c++17","browse": {
                "path": [
                    "${workspaceFolder}"
                ],"limitSymbolsToIncludedHeaders": true,"databaseFilename": ""
            }
        }
    ],"version": 4
}
<p></p>

</code></pre><p></p>

<h2>launch.json</h2>

<pre><code>

    {
        // 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": "debug with gdb (no build)","program": "${fileDirname}/${fileBasenameNoExtension}","MIMode": "gdb","setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true
                    }
                ],"preLaunchTask": "","miDebuggerPath": "/usr/bin/gdb"
            }
        ]
      }


</code></pre>

<h2>tasks.json</h2>

<pre><code>
    {
        "version":"2.0.0","label": "gcc debug build active file - with GTK","command": "/usr/bin/g++","args": [          
            "-g","-pthread","-I/usr/include/cairo","-I/usr/include/glib-2.0","-I/usr/lib/x86_64-linux-gnu/glib-2.0/include","-I/usr/include/pixman-1","-I/usr/include/uuid","-I/usr/include/freetype2","-I/usr/include/libpng16","${file}","-lX11","-lm","-lfltk","-Wall","-o","${fileDirname}/${fileBasenameNoExtension}"
        ],"options": {
            "cwd": "/usr/bin"
        },"problemMatcher": [
            "$gcc"
        ],"isDefault": true
        }
      }     
</code></pre>