0

I'd like to use augeas on my Ubuntu. I've installed the libaugeas-dev apt package, that installed augeas.h file in /usr/include directory. Now I'd like to call some augeas functions.

The first one is augeas *aug_init(const char *root, const char *loadpath, unsigned int flags). I try to use it with the following code

import std.string;

struct augeas;

extern (C) augeas *aug_init(const char *root, const char *loadpath, uint flags);

void main() {
    auto x = aug_init(std.string.toStringz("/"), 
                  std.string.toStringz(""), 
                  0);   
}

The code compiles, but the linker cannot find the aug_init function (undefined reference toaug_init'`). How can I tell him to find it?

Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68

1 Answers1

1

All that was needed is to put the following entry in the dub.json:

"libs": ["augeas"]

So the whole dub.json is this:

{
    "name" : "aug-tool",
    "description" : "Hello World",
    "dependencies" : {  },
    "libs": ["augeas"]
}
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
  • 1
    Generally speaking, you just need to tell the linker to include the library. `dub` can do it. `dmd` can do it itself with two things: you can add `pragma(lib, "augeas");` to your source file you are compiling or `-L-laugeas` to the build command line. `gdc` and `ldc` also support the `-L-l` command I believe. Or if you link separately, just pass `-laugeas` to the `ld` command line. – Adam D. Ruppe Oct 29 '15 at 13:42