Undefined reference -- Local symbol

920 views Asked by At

I am trying to add a new function "pa_context_set_sink_input_paused" to a c file. This c file is part of pulseaudio. I was able to able and successfully compile pulseaudio too.

The code I added to the c file (which has many other functions defined and those are getting declared as global).

pa_operation* pa_context_set_sink_input_paused(pa_context *c, uint32_t idx, int pause, pa_context_success_cb_t cb, void *userdata) 
{
  pa_operation *o;
  pa_tagstruct *t;
  uint32_t tag;

  pa_assert(c);
  pa_assert(PA_REFCNT_VALUE(c) >= 1);

  PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
  PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
  PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
  //PA_CHECK_VALIDITY_RETURN_NULL(c, pa_cvolume_valid(volume), PA_ERR_INVALID);
PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 11, PA_ERR_NOTSUPPORTED);

  o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);

  t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_INPUT_PAUSE, &tag); // ADD A NEW COMMAND 
  pa_tagstruct_putu32(t, idx);
  pa_tagstruct_puts(t, NULL);
  pa_tagstruct_put_boolean(t, pause);
  pa_pstream_send_tagstruct(c->pstream, t);
  pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);

  return o;
}

In header file, the function is declared like this

/** Set the pause of a sink input stream specified by its index */

pa_operation* pa_context_set_sink_input_paused(pa_context *c, uint32_t idx, int pause,   pa_context_success_cb_t cb, void *userdata); //ADDED BY SATHISH

Compiling like so:

$ gcc pa_listclients_pause.c -o pa_listclients_pause -L /home/sathish/Desktop/pulseaudio-4.0/build/src/.libs/ -lpulse
 /tmp/ccueP47b.o: In function `pa_get_devicelist':
 pa_listclients_pause.c.text+0x6cb): undefined reference to `pa_context_set_sink_input_paused'
 collect2: error: ld returned 1 exit status

But when I try to run a program using this new function, it returns me "undefined reference".

I tried to run the nm command and check whether the new function is present in libpulse.so

The function returns me it has found it..

$ nm -A *.so | grep "pa_context_set_sink_input_paused"
libpulse.so:0001d4a0 **t** pa_context_set_sink_input_paused

It is identified as Local symbol with the letter "t".

I am not able to comprehend what is happening. Can you help me with this ??

Thanks, Sathish

Update:-

Thanks Guys,

Your pointers helped me to narrow down close to a solution.. I edited my Makefile process to expose my new function as a "GLOBAL SYMBOL". 

In explanation, there was a file named "map-file" which holding which functions become as global and local. I added my function into the global part of the file.. These seems to have temporarily solved the issue..

I have added the new error I am facing as a seperate question.

http://stackoverflow.com/questions/20702888/relocation-error-while-running-binary

Any pointers on the new issue ??

Thanks, Sathish

1

There are 1 answers

2
AudioBubble On

This is example that demonstrates a similar problem:

In my shared library:

static void test_func_1()
{
}

void test_func_2()
{
}

nm shows:

>nm -C ./libmylib.so |  grep test
000000000000062a T test_func_2()
0000000000000624 t test_func_1()

And when is linking a main program with this library:

int main()
{
  test_func_1();
  test_func_2();

  return 0;
}



>g++ -g -m64 main.cpp -o main -L. -lmylib
/tmp/cciphwuO.o: In function `main':
/main.cpp:32: undefined reference to `test_func_1()'
collect2: ld returned 1 exit status

Or:

void test_func_1()
{

}
void __attribute__ ((visibility ("default"))) test_func_2()
{

}

and building with -fvisibility:

g++ -fvisibility=hidden -m64 -shared -g -fpic mylib.cpp -o libmylib.so

give the same problem:

>nm -C ./libmylib.so | grep test
00000000000005c4 t test_func_1()
00000000000005ca T test_func_2()