3

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.

Recker12
  • 39
  • 1
  • 2
  • 4

1 Answers1

5

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.

Evg
  • 25,259
  • 5
  • 41
  • 83
  • Will I also have to modify launch.json as well with similar procedure? – Recker12 Jun 28 '20 at 18:58
  • @Recker12, no, only `tasks.json` and `settings.json`. – Evg Jun 28 '20 at 19:00
  • @Recker12, just try to compile some program that uses Boost and you'll see what's missing. – Evg Jun 28 '20 at 19:12
  • There seems to be a problem. I add them to task.Json in args. ``` "I", C:\\boost\\include\\boost-1_73 ``` and apparently the lambda library is missing now. It still says No such file when I include a boost library – Recker12 Jun 28 '20 at 19:16
  • @Recker12, what is the structure of `C:\boost` directory? Do you have `C:\boost\include\boost-1_73\boost\lambda\lambda.hpp` file? – Evg Jun 28 '20 at 19:23
  • I made the following changes to the original post(See the above).I tried testing the lambda header file and the lambda file doesnt seem to exist. The code and modifications are shown in the the edited post. – Recker12 Jun 28 '20 at 19:25
  • @Recker12, check that the file `C:\boost\include\boost-1_73\boost\lambda\lambda.hpp` exists. – Evg Jun 28 '20 at 19:27
  • I checked the fire directory and it really does exist(through the windows file explorer). I even checked the intellisense to make sure it is correct. – Recker12 Jun 28 '20 at 19:28
  • That's strange. `-I` is all you need to compile your code with Boost.Lambda. Either the directory `C:\boost\include\boost-1_73\boost\lambda` does not really exist or there is a problem with backslashes. That's how I can compile your program on my machine: `g++ test.cpp -I /../boost_1_73_0`. – Evg Jun 28 '20 at 19:34
  • I am using coderunner to compile the code. Maybe I have to change that as well – Recker12 Jun 28 '20 at 19:37
  • @Recker12, add `-I` option to CodeRunner: `cd $dir && g++ *.cpp -o $fileNameWithoutExt -I && $fileNameWithoutExt.exe`. – Evg Jun 28 '20 at 19:41
  • It finally works. It multiplies for every integer I put in 3 and prints it out right? – Recker12 Jun 28 '20 at 20:03
  • @Recker12, yes. – Evg Jun 28 '20 at 20:07
  • I also got a question whats the point of having a linker folder in the first place if we are never going to use it. I am still bit confused about how external libraries work in C++. Do all external folders have linker folders? – Recker12 Jun 28 '20 at 20:08
  • @Recker12, some libraries are header-only and need no linking at all. Some libraries have `.cpp` files and should be compiled and then linked against. `Boost.Lambda` is header-only, you don't have to specify any linking options to use it. – Evg Jun 28 '20 at 20:11
  • I will have to use various linkers provided in the linker folder right if it needed to be linked? There are many linkers provided in the boost library right? – Recker12 Jun 28 '20 at 20:17
  • @Recker12, you link only against libraries that you actually use. You don't have to specify all of them. (Linker is a program that links object files together.) – Evg Jun 28 '20 at 20:19
  • will I usually specify the linker inside the program or through the command? I was wondering if there was way to automate the linking process by getting the name of the linker in order for code runner to run with a specific linker. I wanted to find if there was a way so that I dont have to specify the linkers name everytime. See the modified code for code runner to see if I am doing it correctly? – Recker12 Jun 28 '20 at 20:31
  • @Recker12, `-L` is for library path (like `-I`), `-l` is for a particular library to link against (like `#include`). In general, you need both. I've never used CodeRunner. To automate the process, you can [use](https://stackoverflow.com/questions/3897839/how-to-link-c-program-with-boost-using-cmake) `CMake`. It will simplify things considerably. Typically we don't run compilers manually and don't specify all these `-I`, `-L` and `-l` by hand. – Evg Jun 28 '20 at 20:36