1

I've been trying to use GLib in a project. I work with XCode. I downloaded Glib via Homebrew:

brew install glib

I then run

brew test glib

Which outputs

/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

So, I copied all the -I arguments, and pasted them into XCode -> Project Settings -> Build Settings -> Other C Flags.

In a .c file inside my XCode project I have

    GList  *processList_p = NULL;      /* Pointer to the process list */

If I compile everything works, but then if I call a function from GLib, such as

//Create the new list element, append it to the list and return the pointer.
return g_list_append(processList, newProcess);

I get the error

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)

I really have no idea what's going on, any help would be greatly appreciated.

4 Answers 4

4

see Setting C++ compile flags in xcode

in short:
add result of
pkg-config --cflags --libs glib-2.0
to Build Settings -> Linking -> Other Linker Flags NOT Build Settings -> Custom Compiler Flags -> Other C Flags

for some reason using 'pkg-config --cflags --libs glib-2.0' directly does not work yielding:

clang: error: no such file or directory: 'pkg-config --cflags --libs glib-2.0'
Sign up to request clarification or add additional context in comments.

Comments

2

As @Dash83 said, it's a linker issue. You need to let compiler to know the locations.

Outputs on my machine:

$ 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

Pass them to clang:

$ clang your_program.c -o your_program `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`

It compiles on my side.

1 Comment

To add to this using ` is very important over ' i found on mac.
0

That is a linker problem my friend. I work with glib on vim on the console and came across your question looking for a quick start guide to use glib in xcode, so I can't really tell you how to fix it on xcode, but I can guarantee you that's a problem with the linker options/flags.

2 Comments

What I can tell you though, is that I use this command to pass the correct flags to my linker: pkg-config --libs glib-2.0
Thanks, the answer for @raf did the trick, if you're still looking for a solution.
0
  1. install pkg-config if not exists

    brew install pkg-config

  2. list cflags

    pkg-config --cflags --libs glib-2.0

  3. manual choose pkg if not exists

    PKG_CONFIG_PATH=/path/to/pkgconfig/ pkg-config --cflags --libs glib-2.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.