How should the libqmi be linked?

493 Views Asked by At

I've tried to use libqmi but I can't get through the linker. It keeps saying "undefined reference" on libqmi functions. Any suggestions what is needed?

Paths and libraries are available for gcc, the symbols are inside libqmi-glib, looks like everything is in place.

The code is the simplest possible, I think.

int main(int argc, char **argv)
{
    GFile *qmi = g_file_new_for_path("/dev/cdc-wdm0");
    printf("%li\r\n", (long int)(qmi));
    g_object_unref(qmi);
    return 0;
}

And the build goes like this:

gcc -I/usr/local/include/libqmi-glib/ -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ whatever.c -L/usr/local/lib/ -L/usr/lib/x86_64-linux-gnu/ -lqmi-glib -lglib-2.0
1

There are 1 best solutions below

0
On

You're missing the link to libgobject-2 and libgio-2.

Anyway, the best way to compile a program using libqmi is to use pkg-config as that knows all the cflags and ldflags you should be using; e.g. you could probably do this, assuming you installed libqmi in /usr/local:

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig gcc $(pkg-config --cflags qmi-glib) whatever.c $(pkg-config --libs qmi-glib)