带有 Visual Studio Code 的 FLTK 库
Posted
技术标签:
【中文标题】带有 Visual Studio Code 的 FLTK 库【英文标题】:FLTK library with Visual Studio Code 【发布时间】:2020-08-28 12:34:44 【问题描述】:我正在尝试为编程原理和实践中的第 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
【问题讨论】:
【参考方案1】:我通常对 Makefile 感觉更舒服,所以我设置了 VS Code 以在我的项目中使用 Makefile。我在安装 FLTK 后做了以下步骤。
我创建了一个目录,其中包含我所有的源文件、头文件等。假设我有一个FLTK_ex
文件夹,其中包含hello.cpp
及其Makefile
我打开 VS Code,然后 File->Open
并选择文件夹 FLTK_ex
从Terminal
菜单中,我选择Configure Default Build Task...
:在出现的菜单中,我选择Create tasks.json file from template
,然后选择Others
出现一个默认的json文件,我修改为
"version": "2.0.0",
"tasks": [
"label": "Build",
"type": "shell",
"command": "Make",
"problemMatcher": [],
"group":
"kind": "build",
"isDefault": true
]
要编译,请转到Terminal
菜单并选择Run Build Task...
要运行程序,请在Run
菜单中选择Run without debugging
、C++
出现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"
]
为了有效地运行程序,在Run
菜单中再次选择Run without debugging
。
我有 FLTK 1.3.5、macOS Catalina 10.15.5、clang 版本 11.0.3、VS Code 1.47。
为了在 VS Code 中使用 FLTK,我只是按照说明(Readme.OSX.txt
)简单地安装 FLTK 库,Windows 系统有一个类似的文件(README.MSWindows.txt
)。
为FLTK
编写Makefile
的准则是here,如果您需要更多关于Makefile
s 的见解,您可以找到完整指南here 或更简短的介绍here。
【讨论】:
感谢 Eddymage 的回答...您能否解释一下如何在 VS Code 中安装 FLTK 以及如何制作 Makefile?我在 CMake 和 Make 之间徘徊,试图找出使用哪一个……对于更简单的项目,Make 确实是一个更好的选择。非常感谢! @Theodore,是的,我在回答中添加了更多信息:我希望它们有用。【参考方案2】:您尚未指定您使用的 Visual Studio 版本。
-
转到 IDE 目录,查找您的 Visual Studio 版本,然后查找 fltk 解决方案。在 Visual Studio 中启动解决方案。
默认情况下,每当您从发行版启动 FLTK 解决方案时,解决方案配置都是 Debug Cairo。将此更改为调试或发布
检查启动项目 - 它应该是名为 Demo 的项目。
开始构建 - 它也应该构建所有测试可执行文件。
【讨论】:
感谢杯,但我要的是 VS Code 而不是 VS...这是最新的 Visual Studio Code Insiders...【参考方案3】:<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/freetype2",
"/usr/include/libpng16",
"/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"
],
"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)",
"type": "cppdbg",
"request": "launch",
"program": "$fileDirname/$fileBasenameNoExtension",
"args": [],
"stopAtEntry": false,
"cwd": "$workspaceFolder",
"environment": [],
"externalConsole": false,
"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",
"type": "shell",
"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",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-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"
],
"group":
"kind": "build",
"isDefault": true
</code></pre>
【讨论】:
代码示例或修改后的代码应包含对您为解决问题所做的更改的描述。以上是关于带有 Visual Studio Code 的 FLTK 库的主要内容,如果未能解决你的问题,请参考以下文章
转到定义并返回到 Visual Studio Code 中的引用