我一直在尝试在项目中使用GLib。我使用XCode。我通过Homebrew下载了Glib:
brew install glib
然后我跑
brew test glib
哪个输出
/usr/bin/clang -o test test.c -I/usr/local/Cellar/glib/2.36.3/include/glib-2.0 -I/usr/local/Cellar/glib/2.36.3/lib/glib-2.0/include -I/usr/local/opt/gettext/include -L/usr/local/Cellar/glib/2.36.3/lib -L/usr/local/opt/gettext/lib -lglib-2.0 -lintl -Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.9 -isysroot /Applications/Xcode5-DP6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
所以,我复制了所有-I参数,并将它们粘贴到XCode中 - >项目设置 - >构建设置 - >其他C旗帜。
在我的XCode项目中的.c文件中,我有
GList *processList_p = NULL; /* Pointer to the process list */
如果我编译一切正常,但是如果我从GLib调用一个函数,例如
//Create the new list element, append it to the list and return the pointer.
return g_list_append(processList, newProcess);
我收到错误
架构x86_64的未定义符号: “_g_list_append”,引自: Scheduler.o中的_CreateProcess ld:找不到架构x86_64的符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
我真的不知道发生了什么,非常感谢任何帮助。
答案 0 :(得分:2)
正如@ Dash83所说,这是一个链接器问题。您需要让编译器知道位置。
我机器上的输出:
$ pkg-config --cflags glib-2.0
-I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include
$ pkg-config --libs glib-2.0
-L/usr/local/Cellar/glib/2.46.2/lib -L/usr/local/opt/gettext/lib -lglib-2.0 -lintl
将它们传递给clang
:
$ clang your_program.c -o your_program `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`
它汇集在我身边。
答案 1 :(得分:2)
请参阅Setting C++ compile flags in xcode
简而言之:
添加结果pkg-config --cflags --libs glib-2.0
构建设置 - >链接 - >其他链接器标志
NOT Build Settings - >自定义编译器标志 - >其他C旗帜
由于某种原因使用
'pkg-config --cflags --libs glib-2.0'直接不起作用产生:
clang: error: no such file or directory: 'pkg-config --cflags --libs glib-2.0'
答案 2 :(得分:0)
这是我朋友的链接器问题。我在控制台上使用glim on vim并遇到了你的问题,寻找在xcode中使用glib的快速入门指南,所以我无法告诉你如何在xcode上修复它,但我可以向你保证这是一个问题链接器选项/标志。
答案 3 :(得分:0)
安装pkg-config(如果不存在)
brew install pkg-config
列出cflags
pkg-config --cflags --libs glib-2.0
手动选择pkg(如果不存在)
PKG_CONFIG_PATH=/path/to/pkgconfig/ pkg-config --cflags --libs glib-2.0