我一直在尝试在项目中使用 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 -> 项目设置 -> build设置 -> 其他 cflags中。
在我的 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);
我得到了错误
Undefined symbols for architecture x86_64: "_g_list_append", referenced from: _CreateProcess in Scheduler.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我真的不知道发生了什么,任何帮助将不胜感激。
最佳答案
参见 Setting C++ compile flags in xcode
简而言之:
添加pkg-config --cflags --libs glib-2.0
的结果
build设置 -> 链接 -> 其他链接器标志
不build设置 -> 自定义编译器标志 -> 其他 cflags
出于某种原因使用
'pkg-config --cflags --libs glib-2.0' 直接不起作用产生:
clang: error: no such file or directory: 'pkg-config --cflags --libs glib-2.0'
关于c - GLib 在 XCode 中的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18798146/