没有提及 glib 函数

No reference to glib functions

各位。 我正在 ubuntu,使用 glib 资源开发这个应用程序,我写了一个像这样的 makefile:

INCLUDES= -I ./headers
FLAGS= -g

PKGCONFIGCFLAGS= `pkg-config --cflags qmi-glib` `pkg-config --cflags gio-2.0` `pkg-config --cflags gobject-2.0` `pkg-config --cflags glib-2.0` `pkg-config --cflags gmodule-no-export-2.0` `pkg-config --cflags gmodule-2.0`

PKGCONFIGLIBS= `pkg-config --libs qmi-glib` `pkg-config --libs gio-2.0` `pkg-config --libs glib-2.0` `pkg-config --libs gobject-2.0` `pkg-config --libs gmodule-no-export-2.0` `pkg-config --libs gmodule-2.0`

CC=gcc

OBJECTS=./build/qmi_test.o

all: ${OBJECTS}
  $(CC) ${FLAGS} ${INCLUDES} ./sources/main.c ${OBJECTS} -o ./bin/main
./build/qmi_test.o:./sources/qmi_test.c
  $(CC) ${FLAGS} ${INCLUDES}  ${PKGCONFIGCFLAGS} ./sources/qmi_test.c ${PKGCONFIGLIBS} -lm -o ./build/qmi_test.o

您可能会注意到,我插入了我找到的所有 glib 相关资源,因为我一直在 return:

中收到这些资源
/usr/bin/ld: ./build/qmi_test.o: in function `g_autoptr_cleanup_generic_gfree':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28: undefined reference to `g_free'
/usr/bin/ld: ./build/qmi_test.o: in function `qmi_test1':
/home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:24: undefined reference to `g_file_new_for_path'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:25: undefined reference to `g_main_loop_new'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:26: undefined reference to `g_cancellable_new'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:29: undefined reference to `g_main_loop_run'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:31: undefined reference to `g_object_unref'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:32: undefined reference to `g_main_loop_unref'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:33: undefined reference to `g_object_unref'
/usr/bin/ld: ./build/qmi_test.o: in function `Device_Create_Start':
/home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:42: undefined reference to `g_file_get_path'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:45: undefined reference to `qmi_device_new'
collect2: error: ld returned 1 exit status
make: *** [Makefile:13: all] Error 1

我读到调用 gcc 时元素的顺序很重要。但我正在尝试按照此处显示的元素顺序进行操作: glib compiling

欢迎任何帮助或建议。

您需要将库标志 (PKGCONFIGLIBS) 添加到 link 步骤而不是编译步骤:

all: ${OBJECTS}
  $(CC) ${FLAGS} ${INCLUDES} -lm ./sources/main.c ${OBJECTS} ${PKGCONFIGLIBS} -lm -o ./bin/main
./build/qmi_test.o:./sources/qmi_test.c
  $(CC) ${FLAGS} ${INCLUDES}  ${PKGCONFIGCFLAGS} ./sources/qmi_test.c  -o ./build/qmi_test.o