简体   繁体   中英

How to set up boost for Visual studio code

So I basically built the entire boost library and put them in C:\boost\include\boost-1_73. But I got a feeling that I have to include more steps before I can use this library. I followed this guide up until setting it up for visual studio code. So now I am scouring the internet to search how to set it up. Here is the guide that I followed. But I didnt include it in the program_files directory like in the guide.

https://gist.github.com/sim642/29caef3cc8afaa273ce6

In my Task.Json I have

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\new\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
            "args": [
                "-g",
                "${fileDirname}\\**.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",      
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

In my main settings.json I have

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "code-runner.saveFileBeforeRun": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.ignoreSelection": true,
    "haskelly.exec.reuseTerminal": true,
    "C_Cpp.updateChannel": "Insiders",
    "r.rterm.windows": "C:\\Program Files\\R\\R-3.6.1\\bin\\R",
    "vsicons.dontShowNewVersionMessage": true,
    "files.autoSave": "onWindowChange",
    "workbench.colorCustomizations": {},
    "editor.tokenColorCustomizations": null,
    "php.validate.executablePath": "",
    "code-runner.executorMap": {
                        "cpp": "cd $dir && g++ *.cpp -o $fileNameWithoutExt -I C:/boost/include/boost-1_73 -L C:/boost/lib && $fileNameWithoutExt.exe"

    },
    "code-runner.executorMapByFileExtension": {},
    "cmake.configureOnOpen": true,
    "explorer.confirmDelete": false,
    "editor.formatOnSave": true,
    "workbench.statusBar.visible": true,
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "Better Solarized Light",
    "code-runner.clearPreviousOutput": true,
    "code-runner.runInTerminal": true,
    "C_Cpp.loggingLevel": "Debug",
    "explorer.sortOrder": "type",
    "C_Cpp.default.forcedInclude": [],
    "C_Cpp.default.includePath": [
        "C:\\boost\\include\\boost-1_73",
    ],
}

How would I include the linker as well(do I even to include the linker?) or if I am doing it properly it all? Will I need to include the path of boost inside Task? It seems to me that the only I did was include it in the intellisense and I am a bit lost now on how to use it. I would greatly appreciate the help.

Edit I made the changes with the following code modified and I created a CPP file to test the lambda header file

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " ");
}

And apparently the file doesnt exist:

fatal error: boost/lambda/lambda.hpp: No such file or directory
#include <boost/lambda/lambda.hpp>

Note that I am running everything with the visual studio code runner extension.

Some parts of Boost are header-only, some should be linked against.

You should specify Boost include directory both for compiler (add -I to args in tasks.jsons ) and for IntelliSense (in settings.json ). If you don't use parts of Boost that are not header-only, that's basically all you need. Otherwise, you'll have to add -l and -L options in tasks.json to specify which Boost libraries to link against and where to find them.

If g++ is run by some extension, you should add -I , -L and -l options there, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM