vscode linux cmake
目录结构
laolang@laolang-PC:~/code/vscode/cstudy$ tree -a . ├── CMakeLists.txt ├── include │ └── tool.h ├── src │ ├── CMakeLists.txt │ ├── main.c │ └── tool.c └── .vscode ├── c_cpp_properties.json ├── launch.json └── tasks.json 3 directories, 8 files laolang@laolang-PC:~/code/vscode/cstudy$
源码
tool.h
#ifndef TOOL_H #define TOOL_H int sum( int a, int b ); #endif
tool.c
#include "../include/tool.h" int sum( int a, int b ){ return a + b; }
main.c
#include <stdio.h> #include <gtk/gtk.h> #include "../include/tool.h" static void activate(GtkApplication *app, gpointer user_data) { GtkWidget *window; window = gtk_application_window_new(app); gtk_window_set_title(GTK_WINDOW(window), "Hello GNOME"); gtk_widget_show_all(window); } int main(int argc, char *argv[]) { int a = 1; int b = 2; a = 2; a = 3; a = 4; printf("%d + %d = %d\n",a,b,sum(a,b)); GtkApplication *app; int status; app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE); g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); status = g_application_run(G_APPLICATION(app), argc, argv); g_object_unref(app); return (status); }
vscode 配置
launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/bin/kmdatastruct", // 可执行文件 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "preLaunchTask": "compile", // task.json 中的 label "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
task.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "compile", "type": "shell", "command": "if [ ! -d \"./build\" ]; then mkdir build; fi && cd build && cmake .. && make", "group": { "kind": "build", "isDefault": true } } ] }
c_cpp_properties.json
此文件主要配置第三方库的提示 ,配置之后最好重启vscode
{ "configurations": [ { "name": "Linux", "browse": { "path": [ "${workspaceFolder}" ], "limitSymbolsToIncludedHeaders": true }, "includePath": [ "${workspaceFolder}", // 下面的目录来自:pkg-config --cflags gtk+-3.0 "/usr/include/gtk-3.0", "/usr/include/at-spi2-atk/2.0", "/usr/include/at-spi-2.0", "/usr/include/dbus-1.0", "/usr/lib/x86_64-linux-gnu/dbus-1.0/include", "/usr/include/gtk-3.0", "/usr/include/gio-unix-2.0/", "/usr/include/cairo", "/usr/include/pango-1.0", "/usr/include/harfbuzz", "/usr/include/pango-1.0", "/usr/include/atk-1.0", "/usr/include/cairo", "/usr/include/pixman-1", "/usr/include/freetype2", "/usr/include/libpng16", "/usr/include/gdk-pixbuf-2.0", "/usr/include/libpng16", "/usr/include/glib-2.0", "/usr/lib/x86_64-linux-gnu/glib-2.0/include" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
运行
F5
参考
相关推荐
wonner 2020-05-07
adsadadaddadasda 2020-04-15
小惠 2020-03-04
hazing 2020-02-22
oZaoHua 2020-02-16
wbczyh 2020-01-19
82467413 2019-12-31
jackadmi 2019-12-28
Andrea0 2019-12-27
wenjs00 2019-12-14
pointfish 2019-12-14
greent00 2019-11-13
GeorgeTH 2019-10-28
kevinzhangwen 2019-03-10
yhljxy 2014-10-19
cyhgogogo 2012-08-20