0

For example, when writing an NGINX module and needing to include headers from said module, how do I do it?

#include <ngx_core.h>
#include <ngx_http.h>

Naturally, the headers are not found as they don't exist on disk. I doubt the proper way to solve this is to bring in the entire NGINX source's headers just so I can reference the headers in my module.

I'm looking for design-time compiler feedback here, not looking for compile-time supports since the module is built using NGINX's configure script which handles wiring things up for compilation.

More specifically, how do I resolve this in VS Code without bringing in all the NGINX header files into my src dir? Is there some sort of symbols file I need?

If I need to have a top-level lib dir with the headers, that's fine, but I cannot change the include paths within my source files (so I couldn't change the include paths to e.g. ../lib/nginx/ngx_core.h) because this will fail during compile time.

missing headers

Josh M.
  • 26,437
  • 24
  • 119
  • 200
  • 1
    If you want VSC to support you here, you **need** to provide the headers. They don't need to be in your project's source tree, instead use the package manager of your OS to install the development support of this library. -- Since I don't use VSC (it is little more than a smart editor, but not a serious IDE), I can only assume that you should be able to setup your project with paths to installed libraries. – the busybee Nov 09 '22 at 15:29
  • Understood that the headers need to be _somewhere_ in order to make use of them. Not sure if NGINX provides a dev package as you suggest. I couldn't find anything about it, at least. For a traditional C program which build off of some other C code, how would one go about doing this? – Josh M. Nov 09 '22 at 18:36
  • Since the headers are also needed at compile time (and the libraries at link time, and in case of shared libraries at run time, too), you should read the project's documentation about the recommended way. Then you have the headers and you can setup VSC's project. – the busybee Nov 10 '22 at 06:32

1 Answers1

0

I was able to resolve this by cloning the NGINX repo (and others I needed) and adding include paths to my VS Code config for my project so the C/C++ extension can find them.

.vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "~/Projects/third-party/nginx/objs/**",
                "~/Projects/third-party/nginx/src/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

For NGINX, this requires you to download the release/GZip, extract it where you want, and then run ./configure -- this generates some things/headers in objs which are required.

Josh M.
  • 26,437
  • 24
  • 119
  • 200