1
votes

I am trying to compile a simple gearman worker on C. I use mac. Here is the code:

#include <libgearman/gearman.h>
int main(void) {
    gearman_worker_st worker;
    gearman_worker_create(&worker);
    gearman_worker_add_server(&worker, "localhost", 4730);
    return 0;
}

When I try to compile it with:

#gcc test.c 
Undefined symbols for architecture x86_64:
  "_gearman_worker_add_server", referenced from:
      _main in ccLUuf8y.o
  "_gearman_worker_create", referenced from:
      _main in ccLUuf8y.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I know I have to link gcc with gearman but when try:

#gcc test.c -lgearman
ld: library not found for -lgearman
collect2: ld returned 1 exit status

Any ideas?

3
Did you install Gearman on your machine? If so, where did you install it? Since it appears you have the header, the library is probably around somewhere. Did you specify a location to find the headers? If you said -I/some/where/include for the headers, then you should probably say -L/some/where/lib to find the library. I don't seem to have Gearman installed on my Mac; I know I've not installed it, and it doesn't seem to be in /lib, /usr/lib, /usr/local/lib or /Developer. - Jonathan Leffler
I just found out port have not installed gearman properly. Installed it with brew and all works fine. - Ivelin

3 Answers

3
votes

maybe your need to define the lib path, like -L/usr/lib/, use your libgearman.a stored path to substitute -L/usr/lib/

3
votes

maybe your need to define the "include path" and the "lib path", for example, the head file "libgearman/gearman.h" in the /usr/local, the library libgearman.so in the /usr/local/libgearman/lib

the compile command like, gcc -I/usr/local -L/usr/local/libgearman/lib test.c -lgearman

0
votes

As stated here, you have to link it with -lgearman

gcc test.c -lgearman