当前位置:网站首页>Tomato learning notes -vscade configuring makefile (using task.jason and launch.jason)

Tomato learning notes -vscade configuring makefile (using task.jason and launch.jason)

2022-06-12 06:34:00 GitTomato

1. Makefile

2. VScode task and launch Study

3. Configuration and use Makefile


1.Makefile

I used to use Visual Studio Conduct C++ Development of , I have no idea Makefile It's something , I can't understand . Until now, it is necessary to Linux Cross platform development on the system , I knew I was wrong .

Don't talk much , A brief introduction ,Makefile It feels like a simple program after use , This program can simplify a lot g++ Compiling work , From input g++ -o xxx yyy become make Simple commands for . and make It can automatically judge whether the source program has been updated according to the time , So you don't have to compile it all every time .

Makefile The format is as follows :

Target: Source
    Order

Target It's the target file ( It can be .exe It can also be .o),Source It's the source file ( It can be .o It can also be .c .cpp etc. ), Simply speaking make The execution logic of a program is the recursion of a function , amount to Target(Source), and Source It can also be a function

  1. find target, see source, If source Also a target Then recursively enter source function
  2. perform Order, It's usually g++ -o

It is worth noting that ,makefile Can simplify operations , For example, the following table uses some symbols instead of

1            $<              Represents the first matching dependency
2            [email protected]             It means a goal
3            $^              All dependence
4           %.o: %.c      Automatic matching

Therefore, the following template can be formed

cc = g++
prog = target
obj = srouce1.o srouce2.o ...

all: $(prog) clean // It's used here all, The program runs from top to bottom , See all It is equivalent to all As the main program , Automatically called clean It's more convenient 

target: $(obj)
    g++ -o $(prog) $(obj)

%.o: %.cpp
    g++ -c %.cpp

clean:
    rm -f $(obj)

2.VScode task,launch

Ref: Vscode in task and launch Some macro definitions of

launch Equivalent to execution .exe Operation of file , Notes are used where it is worth noting , Other places can directly copy

{
    "version": "0.2.0",
    "configurations": [
    {
        "name": "g++.exe build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // Execute this file 
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}", // If the execution of the program will produce a file, it will be placed here 
        "environment": [],
        "externalConsole": true, // If you use the console, you need to open this 
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\Program Files\\MinGW\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
        ],
        "preLaunchTask": "build" // Need to modify here , Follow task in label It's OK to be consistent 
    }
    ]
}

task Here, it is equivalent to compiling , Usually in vscode Middle configuration c++ Use it like this

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "build", // Follow launch Medium preLaunchTask Agreement 
            "command": "C:\\Program Files\\MinGW\\mingw64\\bin\\g++.exe", // Compilation task 
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
            ]
        }
    ]
}

3. Configuration and use Makefile

I understand launch and task Specific in vscode The function of , We can naturally introduce makefile, Replace task Medium g++ compile , Use make command .

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "cd ${fileDirname}; make", // If you use it directly here make Will find , Very pit 
            "args": [
            ]
        }
    ]
}

原网站

版权声明
本文为[GitTomato]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010608175647.html