#How do I include a library?

7 messages · Page 1 of 1 (latest)

hot ingot
#

I'm a total beginner of C. I know a fair bit of Rust though. I wanted to give C a try. I wanted to write a hello world app, which is not a big deal. So, I've thought "Maybe I can go further. What about writing a CLI app?"

So I've searched for some libraries. There seems to be this answer in SO, but the problem is it's not a cross-platform solution. I was looking for a cross platform thing, so I've found cargs.

The library seemed useful so I wanted to give it a try. Many times before, I've seen some C repos use git submodules for dependency management (kinda?). So, following installation tutorial of cargs, I've done:

git submodule add -b stable [email protected]:likle/cargs.git

I wanted to naturally include this to my hello world source:

// main.c
#include <stdio.h>
#include "cargs.h"

int main()
{
    printf("Hello, World!\n");
}

But, one way or another, whenever I compile, I either get #include errors detected. Please update your includePath. or file or directory not found errors.

I've also tried these:

  • #include <cargs.h>
  • #include "cargs/cargs.h"
  • #include <cargs/cargs.h>

I've also tried compiling the cargs itself with its instructions, by simply doing:

cd cargs
mkdir build
cd build
cmake ..
make

But, none of these seemed to have worked.

I know, it's a noobie question, but I really want to understand how I'd manage the dependencies in C (kinda have a vague idea about it but mostly ignorant).

BTW, I've also learned (correct me if I'm wrong) that #include <> includes from system path while #include "" includes from local path (?). So, does that mean I gotta build cargs and install it system wide? If so, how would I ensure the users have cargs library installed on their machine as well (this is what's called dynamic linking I assume?).

Thanks in advance.

vestal ridgeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

twilit fable
#

The stuff inside the "" are a relative path, from the location of your source file, to the location of the header to include. You'll need to make that path match the repo you're pulling in as a submodule

#

Optionally you can add in a compiler option to add the include directory for the submodule to the compiler's include path, so you only need to specify cargs.h rather than a path

hot ingot
#

Well, I've done it with cmake. Thanks anyway @twilit fable.

vestal ridgeBOT
#

@hot ingot Has your question been resolved? If so, type !solved :)

hot ingot
#

!solved