gpt4 book ai didi

c - 没有引用 glib 函数

转载 作者:行者123 更新时间:2023-12-04 19:26:40 26 4
gpt4 key购买 nike

每个人。
我正在使用 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 相关资源,因为我不断收到这些资源作为返回:
/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) 添加到链接步骤而不是编译步骤:

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

关于c - 没有引用 glib 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70188691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com