c-没有引用glib函数



每个人。我正在开发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

正如你可能注意到的,我插入了我发现的每一个与油嘴滑舌相关的资源,因为我不断收到这个回报:

/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时ellements的顺序确实很重要。但我试图遵循元素的顺序,如下所示:glib编译

欢迎任何帮助或建议。

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

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

相关内容

  • 没有找到相关文章

最新更新