美文网首页
ubuntu下,vscode多个c文件时的配置

ubuntu下,vscode多个c文件时的配置

作者: 柳林风声1 | 来源:发表于2019-11-29 17:26 被阅读0次

如果程序有很多个执行文件,或者需要分别编译debug和release等不同版本,或者需要有不同任务分别完成不同的功能,比如我现在有main.c、source.c和source.h等文件需要编译,我还想编译出debug和release版本。如果按照默认设置,会报错,显示main.c里对其它c函数的引用为“未定义的引用”,collect2: error: ld returned 1 exit status。

要解决这个问题,需要在task.json的args添加一行,如:

"${fileDirname}/source.c",

参考:https://my.oschina.net/wuqingyi/blog/1036686

附上各项设置:

c_cpp_properties.json

{"configurations":

[ {

"name": "Linux",

"includePath": [ "${workspaceFolder}/**" ],

"defines": [ "_DEBUG", "UNICODE", "_UNICODE" ],

"compilerPath": "/usr/bin/gcc",

"cStandard": "c11",

"cppStandard": "c++17",

"intelliSenseMode": "gcc-x64" } ],

"version": 4}  

launch.json

"configurations": [

{ "name": "(gdb) Launch",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/a.out",

"preLaunchTask": "build",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": true,

"MIMode": "gdb",

"setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ]

tasks.json

"tasks": [ {

"label":"build",//这里是launch.json中配置的preLaunchTask字段

"type": "shell",

"command": "gcc",

"args": [

"${fileDirname}/hotel.c",

"-g", "${file}", ],

"problemMatcher": [ "$gcc" ],

"group": { "kind": "build", "isDefault": true } } ]

相关文章

网友评论

      本文标题:ubuntu下,vscode多个c文件时的配置

      本文链接:https://www.haomeiwen.com/subject/hjvgwctx.html