Vscode Multi-file compilation and connection based on Linux and Windows/C + +

Source: Internet
Author: User
Tags iqiyi

Sometimes write small program, do not want to start 2013,vscode is my first choice. Just contact Vscode when, followed the online configuration of a bunch of things, and finally can compile C + +, but a lot of files involved, I have to obediently open vs2013. A few days ago in the configuration of Linux Vscode, suddenly found that a netizen in the Tasks.json command is make, suddenly came to the interest, think since use make, then I just a makefile, and then Ctrl+shift+b, Multi-file compile connection on Vscode the problem is not solved. So began to press the user's configuration to write the Tasks.json. But the final make command failed, said to be unable to find target or something (forget), but I am not reconciled, so Baidu is Google, search for almost two hours have not found an effective solution.

When I look at my configuration again, when I move the cursor over the command, there is a hint "thecommand to be executed." Can is an external program or a shell command.". See the shell command can also feel to vomit blood, feel I wasted precious two hours, obviously with shell script becomes very simple, how simple? Look at the picture

Tasks.json

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/14/fe5136e9a44664f158830732927b1db8.png-wh_500x0-wm_3 -wmp_4-s_3925895305.png "title=" screenshot from 2017-11-12 22-08-52.png "alt=" Fe5136e9a44664f158830732927b1db8.png-wh_ "/>

. make.sh

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/14/d284830aa348c9dbed7e21e53bcaa015.png-wh_500x0-wm_3 -wmp_4-s_1949619370.png "title=" screenshot from 2017-11-12 22-10-10.png "alt=" D284830aa348c9dbed7e21e53bcaa015.png-wh_ "/>

The simple thing is to pass the file's directory ${filedirname} as an argument by Vscode. make.sh, after entering this directory in the script, make a bit.

The following tests pass

Test.h#ifndef _multi_file_test_#define _multi_file_test_#include <stdio.h>void print (); #endif//tesh.c# Include "test.h" void print () {printf ("Hello world!\n");}    Main.c#include "Test.h" int main () {print (); return 0;}

Ctrl+shift+b ago

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/14/d368a97c89b24edfbe3c93a2f8cb1a6f.png-wh_500x0-wm_3 -wmp_4-s_307113813.png "style=" Float:none; "title=" screenshot from 2017-11-14 15-16-44.png "alt=" D368a97c89b24edfbe3c93a2f8cb1a6f.png-wh_ "/>

After Ctrl+shift+b

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/14/43309c45db4bdbdc34376471be223aa2.png-wh_500x0-wm_3 -wmp_4-s_2908942398.png "style=" Float:none; "title=" screenshot from 2017-11-14 15-17-28.png "alt=" 43309c45db4bdbdc34376471be223aa2.png-wh_ "/>

Debug

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/14/3d57969dbc0bcfa34d34a2e7b6a7f19e.png-wh_500x0-wm_3 -wmp_4-s_2414184915.png "title=" screenshot from 2017-11-14 15-27-02.png "alt=" 3d57969dbc0bcfa34d34a2e7b6a7f19e.png-wh_ "/>

At this point, Linux vscode configuration is done, in Windows is actually the same as writing a simple batch, but first to MINGW32, install and configure the gcc/g++ environment, in addition, Mingw32 bin no make.exe, but there is a mingw32-make.exe, change it to make is good, do not change, but the corresponding batch file is written mingw32-make instead of make, not to mention, paste on the Windows configuration diagram

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/14/98a701c9be7ae0fadf7dc60d26d313d2.png-wh_500x0-wm_3 -wmp_4-s_3281585569.png "style=" Float:none "title=" Iqiyi art 20171114153542.png "alt=" 98a701c9be7ae0fadf7dc60d26d313d2.png-wh_ "/>

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/14/6f72fde3022d39d0eda39dd2c25cf505.png-wh_500x0-wm_3 -wmp_4-s_3405848672.png "style=" Float:none "title=" Iqiyi art 20171114153746.png "alt=" 6f72fde3022d39d0eda39dd2c25cf505.png-wh_ "/>

Finally, I'll put my makefile and Launch.json on the way.

Linux under Makefile

. Suffixes:.c. occ=gccsrcs=main.ctest.cobjs=$ (SRCS:.C=.O) exec=mainbuild:$ (OBJS) $ (CC)-O $ (EXEC) $ (OBJS) @echo '------- --------OK---------------'. c.o:$ (CC)-wall-g-o [email protected]-C $<clean:rm-f $ (OBJS) Rm-f $ (EXEC)


Linux under Launch.json

{    // 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":  "(GDB)   Launch ",            " type ": " cppdbg ",              "Request":  "launch",              "program":  "${workspacefolder}/${ Filebasenamenoextension} ", &NBSP;&NBSP;&NBSP;&NBsp;         "args": [],              "Stopatentry": false,              "CWD":  "${workspacefolder}",              "Environment": [],              "Externalconsole": true,             " Mimode ": " gdb ",            " SetupCommands ":  [                {                       "description":  "Enable pretty-printing for gdb",                      "text":  "-enable-pretty-printing",                      " Ignorefailures ": true                 }            ]         }    ]}


Under Windows makefile

.  Suffixes:.c. Occ=gccsrcs=main.c test.cobjs=$ (SRCS:.C=.O) exec=main.exebuild:$ (OBJS) $ (CC)-O $ (EXEC) $ (OBJS) @echo '---------------OK---------------'. C.O: $ (CC)-wall-g-o [email protected]-C $<clean:del $ (OBJS) del $ (EXE C


Under Windows Launch.json

{"Version":  "0.2.0", "Configurations":  [{"name":  "c++ launch  (GDB)",                  //  Configuration Name, The "type":  "cppdbg" will be displayed in the drop-down menu of the launch configuration,                            //  Configuration Type, This is only for cppdbg "request":  "launch",                         //  Request Configuration Type, Can be launch (start) or attach (attach) "Targetarchitecture":  "x86",                 //  generates a target schema, typically x86 or x64, which can be x86, arm, arm64,  Mips, x64, amd64, x86_64 "program":  "${filedirname}/${filebasenamenoextension}.exe",   //  the path of the program that will be debugged "Midebuggerpath": "d:/mingw32/mingw32/Bin/gdb.exe ",  // midebugger path, note here to MinGW path corresponding to" args ":  [" Blackkitty ",  " 1221 ", " # # "],     //  program debugging when the command line parameters passed to the program, generally set to empty can be" stopatentry ": false,                         //  set to True when the program will pause at the entrance of the program, generally set to false "CWD":  "${filedirname}",                   //  working directory when debugging a program, Typically ${workspaceroot} is the directory where the code is "Externalconsole": true                    //  whether to display a console window when debugging, typically set to true display console}]}


This article is from the "11662416" blog, please be sure to keep this source http://11672416.blog.51cto.com/11662416/1981689

Vscode Multi-file compilation and connection based on Linux and Windows/C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.