0

I am trying to create a sample project for myself using Plog library. according to its documentation, I must add its include folder to my include path. SO, I add these Lines to C/C++ configuration in my vs-code:

${default}
${workspaceFolder}/**

and this is my main function:

#include <iostream>
#include "plog/Log.h"
int main() {
    plog::init(plog::debug, "log.txt");
    std::string name;
    std::cin >> name; 
    LOGD << "user entered name :" << name; 
    std::cout << name << std::endl; 
    return 0;
}

but when I run this code I am getting this error:

fatal error: plog/Logger.h: No such file or directory

which plog/Logger.h is referenced by log.h in the main function. plog folder which contains All headers of plog library is located in my project root folder. this is My folder structure:

root
   |_plog
   |    |
   |    |_ all my header files *.h
   |_main.cpp 

Is there any more configuration which I missed? or did I make a mistake in any step?

Navid_pdp11
  • 3,487
  • 3
  • 37
  • 65

3 Answers3

0

Try

#include <plog/Log.h>
dumb
  • 1
  • 5
0

Why do you have ** after ${workspaceFolder}?

First we need to know what the directory structure is. For instance

+-- C:\
    +-- ProgramData
        +-- plog-dist
            +-- plog
                +-- Log.h
            +-- lib
                +-- plog.lib
            +-- bin
                +-- plog.dll
    +-- Users
        +-- Me
            +-- Documents
                +-- myproject

Let us assume that you already have an environment variable setup

setx PLOG=C:\ProgramData\plog-dist

You can either manage this under property pages or you can set it on individual projects. Let us just do the second method because it is easier and has less explaining. Under C++ General Properties, the first line says Additional Include Directories. Add in

$(PLOG)

This will pick up your environment variable PLOG. In your code

#include "plog/Log.h"

VS will look in $(PLOG) for plog/Log.h. If the distribution is

+-- ProgramData
    +-- plog
        +-- Log.h

And the environment variable is

setx PLOG=C:\ProgramData\plog

Then you should just

#include "Log.h"

VS will look in $(PLOG) for Log.h

Next go to the linker section of properties. Here, you will see Additional Library Directories. Add $(PLOG)/lib. This is where it can find plog.lib. If plog.lib lives in $(PLOG) then add $(PLOG). It really depends on what the directory structure is.

Next go to the Input property page. Under Additional Dependencies add plog.lib.

If you set up the PLOG variable and type tree /f %PLOG% from the cmd line, it will tell you where everything is relative to $(PLOG).

cup
  • 7,589
  • 4
  • 19
  • 42
  • I am on linux, and I am just using plog code. I have updated my question about my directory structure and additionally ** means search recursively in a folder for header files (according to vs code docs). – Navid_pdp11 Jul 12 '20 at 19:37
  • In that case you should need to add anything - plog is at the same level as main. Have you got the casing of Log.h correct? Is it log.h? – cup Jul 12 '20 at 19:43
0

Assuming that below is your folder hierarchy:

root
   |_plog
   |    |
   |    |_ Init.h
   |    |_ Log.h
   |    |_ Init.h
   |    |_ Other plog's *.h files
   |_main.cpp 

In that case, adding ${workspaceFolder} to your include paths must suffice.

When you do #include "plog/Log.h", it expects the plog folder to be a direct children of the include paths. As plog folder is a direct child of ${workspaceFolder} directory, this should work.

Shrukul Habib
  • 116
  • 3
  • 4
  • you mean I add just a parent folder like "inc" and move plog into it and then set my include path to "${workspaceFolder}/inc"? – Navid_pdp11 Jul 13 '20 at 05:42
  • this doesn't work for me... instead I use -I argument on g++ compiler according to this link: https://stackoverflow.com/a/6141166/1093228 – Navid_pdp11 Jul 14 '20 at 19:06