c - GLib 在 XCode 中的使用

标签 c xcode glib

我一直在尝试在项目中使用 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/

相关文章:

ios - 如何在 Swift 中退出 "DispatchQueue.main.asyncAfter"

ios - 正则表达式仅用于UITextfield中的名称

Python 找到 glib,但找不到 _glib

c - gsocket(服务器模式)出现错误?

glib - glib中获取线程id(tid)

valgrind 对未初始化值的提示可能是误报吗?

c - 为什么我无法将 unsigned int 指针转换为 unsigned int?

c - 如何在里面工作 printf ?

c - 为什么文本文件中的全文未在服务器端打印?

ios - XCode Swift - MultiPeerConnectivity/MCAdvertiserAssistant 未呈现连接的接受/拒绝对话