2

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
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
PPaweł
  • 21
  • 1
  • 3
    Post the exact error message. – Maxim Egorushkin Jul 10 '19 at 09:46
  • Please post a [mcve] so we can reproduce the problem and help you debug it. – user3629249 Jul 11 '19 at 01:27
  • `C` and `C++` are two different languages. Please pick one – user3629249 Jul 11 '19 at 01:28
  • Exact error message is: /tmp/ccdei99o.o: In function `main': whatever.c:(.text+0x17): undefined reference to `g_file_new_for_path' whatever.c:(.text+0x3f): undefined reference to `g_object_unref' collect2: error: ld returned 1 exit status And yes, C and C++ are different languages. This code can be compiled by both of them and as a final target it'd be C++. – PPaweł Jul 11 '19 at 10:30

1 Answers1

0

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)
Aleksander
  • 640
  • 5
  • 13