How to install third party libraries in a directory and include them as standard C headers

Viewed 154

I'm used to got something like npm i in nodejs, or pip install in python to install/add 3rd party libraries but C has nothing of this.

Say I want to use this orca library and use its headers as I'd use any other standard C headers like including stdlib (I want to be able to include them with <> instead of "") I dont get its build instructions,

  • How would I get autocompletion in vim (I use clang and coc-clangd for C autocompletion) from these headers?

  • How would the compiler know where these headers are located in? As first I thought adding them to the include dir in linux but didnt seem right

  • If I wanted to make a C library for others to use, how would I set up everything for them to use it.

  • If I wanted to use my own headers as standard C ones for my directory, how would do I so? Say I've got the following dir structure

├── CMakeLists.txt
└── src
    ├── include
    │   ├── header1.h
    │   └── header2.h
    ├── implement1.c
    ├── main.c
    └── implement2.c

And in the main.c I want to include header1.h as so...

#include <header1.h>

int main() {
   header1Somefunction();
   return 0;
}

I use cmake for linking c executables.

Some time ago, I had kind of same problem creating a C addon for nodejs, with napi.h header file, where I couldn't include it as a standard header (which was in node_modules/node-addon-api) so I had to create that addon without autocompletion reading examples and docs and instead of napi.h I ended up using node/node_api.h, and I wasn't even able to include it as just node_api.h but node/node_api.h.

0 Answers
Related