cmake vscode 高亮_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

#include

#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

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值