我想使用Codeblocks中的glib解析配置文件。所以我首先想要做的就是按照这里描述的示例进行操作。我的配置文件名为myconfig.cfg,代码文件名为programming.c。我只是复制并粘贴代码,看看glib是否起作用,但不幸的是它没有起作用。我使用sudo apt-get安装了glib2.0,然后找到了glibs中的库所在位置。
我添加了。
当我编译和运行programming.c时,出现了以下错误。
pkg-config --cflags --libs glib-2.0
在这条路径中
project->Build Options->Compiler Settings-> Other Options
我添加了。
-I/usr/include/glib-2.0 -I/usr/lib/arm-linuxgnuebihf/glib-2.0/include
当我编译和运行programming.c时,出现了以下错误。
-------------- Build: Debug in programming ---------------
gcc -Wall -g -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -std=c99 -c /home/pi/Desktop/programming/main.c -o obj/Debug/main.o
g++ -o bin/Debug/programming obj/Debug/main.o /usr/lib/libmysqlclient.so.16
obj/Debug/main.o: In function `main':
/home/pi/Desktop/programming/main.c:22: undefined reference to `g_key_file_new'
/home/pi/Desktop/programming/main.c:26: undefined reference to `g_key_file_load_from_file'
/home/pi/Desktop/programming/main.c:28: undefined reference to `g_log'
/home/pi/Desktop/programming/main.c:34: undefined reference to `g_slice_alloc'
/home/pi/Desktop/programming/main.c:37: undefined reference to `g_key_file_get_string'
/home/pi/Desktop/programming/main.c:39: undefined reference to `g_key_file_get_locale_string'
/home/pi/Desktop/programming/main.c:41: undefined reference to `g_key_file_get_boolean_list'
/home/pi/Desktop/programming/main.c:43: undefined reference to `g_key_file_get_integer_list'
/home/pi/Desktop/programming/main.c:45: undefined reference to `g_key_file_get_string_list'
/home/pi/Desktop/programming/main.c:47: undefined reference to `g_key_file_get_integer'
/home/pi/Desktop/programming/main.c:49: undefined reference to `g_key_file_get_double_list'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
11 errors, 0 warnings
我有所遗漏吗?我也尝试使用libconfig以同样的方式操作,但是我仍然遇到了未定义的引用。问题在于路径吗?
更新
使用pkg-config --libs glib-2.0命令返回了-lglib-2.0
在Codeblocks中,我将它(lglib-2.0)插入了
project->Build Options->Linker Settings-> Link Libraries
现在我遇到了这个错误:
**(process:3751): ERROR ** No such file or directory
Trace/breakpoint trap