Search code examples
cvici

Linking to a header file of the VICI library


I'm trying to programm an own application for VICI which is some kind of an interface for the strongswan application (https://www.strongswan.org/apidoc/md_src_libcharon_plugins_vici_README.html)

There exists an example how to build a simple VICI client:

#include <stdio.h>
#include <errno.h>
#include <string.h>

#include <libvici.h>

int main(int argc, char *argv[])
{
    vici_conn_t *conn;
    int ret = 0;

    vici_init();
    conn = vici_connect(NULL);
    if (conn)
    {
        /* do stuff */
        vici_disconnect(conn);
    }
    else
    {
        ret = errno;
        fprintf(stderr, "connecting failed: %s\n", strerror(errno));
    }
    vici_deinit();
    return ret;
}

Up to now I tried really many ways to build this application properly with gcc, but everytime I get errors because either there header files missing, or there exist undefined references and so on. I can't find a way to succeed. The header file libvici.h lies in a folder /folder1/folder2 so I tried to link to it via gcc:

gcc myapp.c -L/folder1/folder2

But I get an error of undefined reference to 'vici_init' (which is a function in the VICI application)

I also tried to link to the library files /usr/lib/ipsec/libvici.a via

gcc myapp.c -L/usr/lib/ipsec

But the same error as above.

It would be very nice if somebody can tell me how to include/link the header files properly so that I can use the VICI application.

Thank you!


Solution

  • I finally found a solution to my problem. The command above is almost correct, but the order of the arguments to gcc isn't.

    This works for me:

    gcc -L/usr/lib/ipsec -lvici myapp.c