How to use the head file in my CPP project under WSL?

Sorry for confusion. I am a C++ beginner.
I have been successfully make the lib,make testall and bin/examples/pke/simple-integers all work.
However, it fails to use this lib in my own C++ project in another location, the gcc fails to find the head file, openfhe.h for example. Specifically:

#include “openfhe.h”
^~~~~~~~~~~

The error reports that

There is no such file in the directory gcc

I guess the lib doesn’t be add in the gcc env. So how can I solve this problem and use OpenFHE to build my project?

By default, the library gets installed in /usr/local and openfhe.h will be in /usr/local/include/openfhe/pke/. So, please check if it is there. If it is not, then rerun “make install”. Most likely you would need the admin rights to install OpenFHE.
For your own example:

  1. make a new directory where you keep your own “lance_project.cpp” file.
  2. copy CMakeLists.User.txt from openfhe-development/ to the new directory and rename it to CMakeLists.txt
  3. Open CMakeLists.txt for editing and add a new line as it is suggested in the comments in the very end of CMakeLists.txt. Something like this:
    add_executable( test lance_project.cpp)
  4. make a new directory build and “cd build”
  5. and after that the procedure is very similar to building and running examples in OpenFHE:
  • cmake …
  • make
  • and, finally, run ./lance_project
    Good luck!

Thanks a lot for your help!
I have seemly solved this problem by exporting the head-file path to gcc compiler. Specifically, I changed the \etc\profile in WSL with following code:

export CPLUS_INCLUDE_PATH=/usr/local/include/openfhe/pke:$CPLUS_INCLUDE_PATH

What a silly method hhhh.
I will try your scheme later, but I am facing another problem. And I post a new topic for this.Fail to run example with error: ‘MATHBACKEND’ was not declared in this scope

As someone who learned C++ relatively recently (compared to Dmiriy), I think you should try and focus on this first (header/imports) before jumping to the other issue (MATHBACKEND). The less moving parts the easier it’ll be to figure out :slight_smile:

It works!
I follow your scheme, adding add_executable( test test_lance.cpp) in the end of CMakeLists.txt, then I make and run ./test, the cpp file is successfully excuted.

However, I suffer the same error when I want to run the “simple-real-numbers.cpp” example in VS Code editor.

/usr/bin/g++ -fdiagnostics-color=always -g /home/lance/code/cpp_test/test_lance.cpp -o /home/lance/code/cpp_test/test_lance
/home/lance/code/cpp_test/test_lance.cpp:38:10: fatal error: openfhe.h: No such file or directory
   38 | #include "openfhe.h"
      |          ^~~~~~~~~~~
compilation terminated.

According to official document, I add following comments in setting.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/openfhe/core", // I added these three lines.
                "/usr/local/include/openfhe/pke",
                "/usr/local/include/openfhe/cereal"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

launch.json is:

takes.json is:

{
    "tasks": [
        {

            "label": "buildCmake",
            "type": "shell",
            "command": "cd build && rm CMakeCache.txt && cmake .. -DCMAKE_BUILD_TYPE=Debug && make",    
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

How I fix this problem?

we dont support VC++: Installing OpenFHE on Windows — OpenFHE documentation

Sorry for confusion. I use Visual Studio Code as IDE instead of VC++, because the document of OpenFHE guides to configure the Visual Studio Code.

Do you mean the OpenFHE doesn’t support Visual Studio Code now?
Could you please tell me what other IDE I can use?

Please read the OpenFHE documentation: Welcome to OpenFHE’s documentation! — OpenFHE documentation

Hey all! I’m going to close this topic because it seems like this discussion is moving into a question already asked elsewhere How to run the example in Visual Studio Code? - #4 by lance

@lance I suggest editing the question in that post to include the details from this comment: How to use the head file in my CPP project under WSL? - #5 by lance

Thanks!