Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

There are two libraries:

First library - libhello.so

cat hello_child.c

#include "hello_child.h" 

int put_my_msg( char *messg ) {
   printf( messg );
   return -1;

cat hello_child.h
#include <stdio.h>
int put_my_msg( char* );

to build th command:

gcc -c -fpic -o hello_child.o hello_child.c
gcc -shared -o libhello.so hello_child.o

Here all is well, the library is created

Second library - libhello2.so

cat hello_child2.c
#include "hello_child.h"
#include "hello_child2.h" 

int put_my_msg2( char *messg ) {
   put_my_msg( messg );
   return -1;

cat hello_child2.h
#include <stdio.h>
int put_my_msg2( char* );

to build th command:

gcc -c -fpic -o hello_child2.o hello_child2.c
gcc -shared -L. -lhello -o libhello2.so hello_child2.o

This library is also normal is going, but when viewing the list of libraries linking command:

ldd libhello2.so
linux-gate.so.1 => (0xb77dc000)
libc.so.6 => / lib/i386-linux-gnu/libc.so.6 (0xb7619000)
/lib/ld-linux.so.2 (0xb77dd000)

that is, we do not have a dependency library libhello.so

as a result in the test program hello_main.с:

# include "hello_child2.h"

int main (int argc, char * argv []) {
    char * messg = "Hello world! \ n";
    int res = put_my_msg2 (messg);
    return res;

when it is compiled

gcc hello_main2.c-Bdynamic-L. /-lhello-lhello2-o hello

an error:

.//libhello2.so: undefined reference to `put_my_msg'

I'm using Ubuntu 12.04 x86, gcc 4.6.3 (Ubuntu / Linaro 4.6.3-1ubuntu5)

How to fix this error?

I tried the same on OpenSUSE and there is no such problem.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.