libmm-glib.la: file not recognized: File format not recognized

Aleksander Morgado aleksander at aleksander.es
Tue Mar 29 18:44:07 UTC 2016


Hey,

>
> I'm writing a simple C code to interface to MM to be able to read some
> stats. I'm following the mmcli examples as was suggested earlier.
>
> All I'm currently reading is mm_modem_get_manufacturer (ctx->modem); so
> nothing complex.
>
> I have the following headers:
>
> #include "config.h"
>

This config.h is only needed if building from within the MM source
tree (unless you have your own config.h).

> #include <stdio.h>
> #include <stdlib.h>
> #include <locale.h>
>
> #define _LIBMM_INSIDE_MMCLI
>

You must not define this symbol for external programs. This is a
symbol that should only be included within mmcli sources.

> #include <glib.h>
> #include <gio/gio.h>
>
> #include <libmm-glib/libmm-glib.h>
> #include "../libmm-glib/mm-modem.h"
>

You should only #include <libmm-glib.h>.

> #include "mmcli.h"
> #include "mmcli-common.h"
>

This should only be needed from within mmcli sources.

> I have a simple Makefile for it too:
> CC=gcc
>
> top_build_prefix = ../
> top_builddir = ..
> top_srcdir = ..
> MMCLI_CFLAGS = -pthread -I/usr/include/glib-2.0
> -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/gio-unix-2.0/
> CFLAGS= \
>         $(MMCLI_CFLAGS) \
>         -I$(top_srcdir) \
>         -I$(top_srcdir)/include \
>         -I$(top_builddir)/include \
>         -I$(top_srcdir)/libmm-glib \
>         -I${top_srcdir}/libmm-glib/generated \
>         -I${top_builddir}/libmm-glib/generated
>
> MMCLI_LIBS = -lgio-2.0 -lgobject-2.0 -lglib-2.0
>
> LDFLAGS=$(MMCLI_LIBS) \
>         $(top_builddir)/libmm-glib/libmm-glib.la
>
>
>
> all: ali
>
> build: ali.o
>         $(CC) ali.o -o ali
>
> ali.o: ali.c
>         $(CC) $(CFLAGS) $(LDFLAGS) $(MMCLI_LIBS) ali.c
>
> clean:
>         rm *o ali
>

libmm-glib uses pkg-config, so you can use that better instead of
hand-coding the CFLAGS and LDFLAGS. This also allows you to compile a
program from out of the ModemManager source tree, which you should.
See example below.

>
> The code is placed in cli/ alongside mmcli source codes.
>

Yeah no need to do that.

> When I build it with the makefile I get the following error:
> root at beaglebone:~/MM/ModemManager-1.4.12/cli# make -f aliMake
> gcc -pthread -I/usr/include/glib-2.0
> -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/gio-unix-2.0/
> -I.. -I../include -I../include -I../libmm-glib -I../libmm-glib/generated
> -I../libmm-glib/generated -lgio-2.0 -lgobject-2.0 -lglib-2.0
> ../libmm-glib/libmm-glib.la -lgio-2.0 -lgobject-2.0 -lglib-2.0 ali.c
> ../libmm-glib/libmm-glib.la: file not recognized: File format not recognized
> collect2: ld returned 1 exit status
> make: *** [ali.o] Error 1
>
>
> But when I make mmcli it compiles fine.
>
> What am I doing wrong/missing?

Don't build within MM sources, you can compile your external program
easily e.g. like this:
$ gcc -o test-mm `pkg-config --cflags --libs mm-glib` test-mm.c

See attached tester program for an out-of-tree example.

-- 
Aleksander
https://aleksander.es
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-mm.c
Type: text/x-csrc
Size: 2211 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/modemmanager-devel/attachments/20160329/b120768a/attachment.c>


More information about the ModemManager-devel mailing list